Selenium Java

 

 


Random notes:

 


You can also use Pagefactory, and have something like:

@FindBy(how = How.NAME, using = "logonName")
private WebElement logonNameField;

@FindBy(how = How.NAME, using = "password")
private WebElement passwordField;

Now, as for How., you can have:

  1. CLASS_NAME
  2. CSS
  3. ID
  4. ID_OR_NAME
  5. LINK_TEXT
  6. NAME
  7. PARTIAL_LINK_TEXT
  8. TAG_NAME
  9. XPATH
  10. class

Or you can use your own DOM Search plus Xpath, that would be outside of WebDriver API , but it should work.

 


You want:

private boolean isElementPresent(WebDriver driver, By by){
    return driver.findElements(by).count == 0;
}

findElements() is better for this than findElement() because it won't wait if the element isn't present. If you're running with implicit waits turned on, fildElement() will time out looking for the element (that's the exception you're catching), and it will take a while