2

Explicit wait is not working for Firefox (52.4.0 (64-bit))below is my code:

public static void main(String[] args) {
    System.setProperty("webdriver.gecko.driver", "C:\\Drivers\\geckodriver.exe");
    WebDriver driver = new FirefoxDriver();
    driver.get("https://XXXX/XXXXX/XX/login");
    driver.findElement(By.id("userId")).sendKeys("XXXXX");
    driver.findElement(By.id("password")).sendKeys("XXXXX");
    driver.findElement(By.id("submit")).click();
    WebDriverWait wait = new WebDriverWait(driver, 50);
    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//span[text()='Viewer']")));
    driver.findElement(By.xpath("//span[text()='Viewer']")).click();
}

I have to use Explicit wait here in any case as elements doesn't get loaded in fixed time. I have searched lot in google but didn't find any code working for me.

user3729220
  • 230
  • 2
  • 8

3 Answers3

2

As per your code attempt it seems you are waiting for the WebElement through WebDriverWait and then trying to invoke click() method. In your code you have used the clause presenceOfElementLocated with ExpectedConditions, which as per the documentation doesn't confirms if the WebElement is Displayed and Enabled as well.

A better solution will be to modify the clause for ExpectedConditions where instead of presenceOfElementLocated we have to use elementToBeClickable as follows:

WebDriverWait wait = new WebDriverWait(driver, 50);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[text()='Viewer']")));
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
1

You are using presenceOfElementLocated. As per documentation:

An expectation for checking that an element is present on the DOM of a page. This does not necessarily mean that the element is visible.

You have to be sure that you are waiting on the element the correct expected condition.

Davide Patti
  • 3,391
  • 2
  • 18
  • 20
1

as per @DebanjanB , i just it is not an good idea to use presenceOfElementLocated instead it is always better to use elementToBeClickable so correct code should be:

public static void main(String[] args) {
    System.setProperty("webdriver.gecko.driver", "C:\\Drivers\\geckodriver.exe");
    WebDriver driver = new FirefoxDriver();
    driver.get("https://XXXX/XXXXX/XX/login");
    driver.findElement(By.id("userId")).sendKeys("XXXXX");
    driver.findElement(By.id("password")).sendKeys("XXXXX");
    driver.findElement(By.id("submit")).click();
    WebDriverWait wait = new WebDriverWait(driver, 50);
    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[text()='Viewer']")));
    driver.findElement(By.xpath("//span[text()='Viewer']")).click();
}
iamsankalp89
  • 4,607
  • 2
  • 15
  • 36