I’m a newbie to selenium.
I’m trying to traverse all the elements in a dropdown box on a webpage with a lot of sub elements. I’m doing this to get all the href attributes on all the options in the select tags.
I’m finding elements using the Xpath expressions.
I’m using Selenium WebDriver along with FireFox browser. The results are what I expect but the test is extremely slow.
If there any way in which I can make the test faster by using any alternative approach?
This the code I’m using –
private void captureElements(String xpath)
{
List<WebElement> list=null;
if((list=driver.findElements(By.xpath(xpath)))!=null){
int length = list.size(); int i=length;
while(i>0){
WebElement ele = list.get(length-i);
Actions builder = new Actions(driver);
builder.moveToElement(ele).build().perform();
LogElementToExcel(ele);
int index = length-i+1;
String newxpath = xpath.replace("/a", "["+index+"]/ul/li/a");
captureElements(newxpath);
i--;
}
}
}
You are running tests in firefox which has native xpath engine. So it’s hard to tell why your test is slow unless you provide the code. Xpath is slow in IE because IE doesn’t have a native xpath engine but that doesn’t seem to be your issue at this point.
I am thinking below would be faster than your xpath solution. Give it a shot.