2

I am using the latest version of webdriver. While I can select the right links it seems as the wrong links are actually clicked.

Here is some code to use for Google. What it does is simply clicking a result of a Google Search.

  @FindBy (id ="ires")
  private WebElement searchResults;

   public void clickResult(int i) {
    initPage();
    List<WebElement> resultLinks = getSearchResultLinks();
    resultLinks.get(2).click();    
  }

  private List<WebElement> getSearchResultLinks (){
    return searchResults.findElements(By.className("l"));
  }

1 Answers1

2

First, you have an error in your clickResult, met6hod: you should pass the i to the resultLinks.get:

public void clickResult(int i) {
    initPage();
    List<WebElement> resultLinks = getSearchResultLinks();
    resultLinks.get(i).click();    
  }

Another possible problem may be that the list returned by getSearchResultLinks is a zero based array, so to get the first search result you have to call clickResult(0) and so on. This may be obvious to programmer, but testers may have problems here :)

Sergii Pozharov
  • 17,366
  • 4
  • 29
  • 30
  • Hi the i thing is true this came into the game during testing. However this is not the problem. The indexing isn't the problem either. If I access the href attribute I get the correct link target. However as soon as I call click it clicks somewhere completely different – Alois Reitbauer Nov 15 '10 at 07:08
  • If you are using InternetExplorerDriver, there are some issues that may cause this: - if zoom is not 100% it may have troubles to click an element - if the link is near the edges of the browser window it may have problems clicking on it - if link text is too long or have some special characters, it may have troubles clicking on it What driver are you using? have you tried the Firefox one? – Sergii Pozharov Nov 15 '10 at 11:03