1

So heres the thing I have to do. I want to go to a site like http://www.walmart.com/catalog/allReviews.do?product_id=16561041 and expand all the reviews on the page. I require the reviews to be fully open because I need to collect this data. My current code works but is extremely slow.

public void clickAllLinks(String linkText){
    for(int j = 0; j < 20 ; j++){
        try{
        if(driver.findElement(By.linkText("(read full review)")).isDisplayed())
            driver.findElement(By.linkText(linkText)).click();
        }catch(NoSuchElementException e){break;}
    }
}

Im using selenium 2.21 with firefox driver. Does anyone have any suggestions? I am fairly new to using selenium so my knowledge of it is fairly limited compared to most of you out there.

1 Answer 1

1

Use driver.findElements() instead of driver.findElement(). Then simply click all links one by one in loop.

If this will not help - try to profile you code. Also you can write some js to click all links.

1
  • Thank you, that was so simple and yet it sped things up to 1/10th the time of the original
    – AlbChu
    May 25, 2012 at 0:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.