0

I initialized and set my driver as below:

System.setProperty("webdriver.firefox.bin", Vars.FFPATH);
System.setProperty("webdriver.gecko.driver", "C:\\geckodriver.exe");
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setAcceptInsecureCerts(true);
WebDriver driver = new FirefoxDriver(desiredCapabilities);
driver.navigate().to(siteurl);
driver.manage().timeouts().implicitlyWait(30, SECONDS);

I assume, it should wait for 30 seconds before executing rest of code. It doesn't work, there is no waiting time, execution takes only 8 seconds. I tried to use FluentWait to to make some waiting time by waiting for elemnt to be clickable.

FluentWait<WebDriver> wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.elementToBeClickable(webpage.linput));

Error message:

java.lang.NullPointerException at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:787) at org.openqa.selenium.support.ui.FluentWait.(FluentWait.java:102) at org.openqa.selenium.support.ui.WebDriverWait.(WebDriverWait.java:71) at org.openqa.selenium.support.ui.WebDriverWait.(WebDriverWait.java:45)

I checked variable webpage.linput with Logger and it has a valid value, the xpath for the given element, so it is not null. Variable created here:

By linput = By.xpath("//*[@id=\"formA\"]/p[1]/label");

Versions:

WebDriver 3.5.2
GeckoDriver 0.18.0
Firefox 55.0.3
plaidshirt
  • 5,189
  • 19
  • 91
  • 181

3 Answers3

1

Couple of things.

implicitlyWait

it shouldn't be

driver.navigate().to(siteurl);
driver.manage().timeouts().implicitlyWait(30, SECONDS);

it should be

driver.manage().timeouts().implicitlyWait(30, SECONDS);
driver.navigate().to(siteurl);

Also, implicit wait doesn't pause the exeuction, it just increase the timeout for every action (i.e. findElement, click)

pageLoadTiemout:

Also, if you want to increase the time out for page load implicit wait is not going to help. you should use pageLoadTiemout

check the following page. https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/WebDriver.Timeouts.html

For second problem

user webdriver wait rather than fluent wait.

WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.elementToBeClickable(webpage.linput));

and if you just want to pause the execution

use Thread.sleep() method.

Gaurang Shah
  • 11,764
  • 9
  • 74
  • 137
1

A few words about Implicit Wait:

ImplicitWait as per the official documentation is to configure the WebDriver instance i.e. the driver to poll the HTML DOM for a certain amount of time (interms of NANOSECONDS, MICROSECONDS, MILLISECONDS, SECONDS, MINUTES, HOURS or DAYS) when trying to find an element or elements if they are not immediately available. The default setting is 0 which means the driver when finds an instruction to find an element or elements, the search starts and results are available on immediate basis.

As per your code you have initialized the ImplicitWait as:

driver.manage().timeouts().implicitlyWait(30, SECONDS);

But the End Point is never called. To know more about ImplicitWait you can have a look at this discussion.

Finally, you have initiated FluentWait but the implementation of FluentWait is not present in your code. Your code resonates the implementation of WebDriverWait. Hence you face NullPointerException

Solution:

Without any further lines of code in your code block I feel you don't need any of the waits (ImplicitWait, WebDriverWait, FluentWait). You can proceed without initiating any of them.

Update:

Incase you need to wait for any particular state of any particular WebElement, Selenium have provided the in-built ExplicitWait i.e. WebDriverWait where you can choose from 50 odd ExpectedConditions conditions. See this documentation and this discussion for more details.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • You said: "You can proceed without initiating any of them." In this case how could I wait during execution? If I execute it without wait, I get error, that element is not found. I used the exact same code with Webdriver 2.53 and it was working earlier. – plaidshirt Aug 30 '17 at 10:09
  • @plaidshirt Good Question, Incase you need to wait for any particular state of an particular element Selenium have provided the `ExplicitWait` i.e. `WebDriverWait` where you can choose from 50 odd `ExpectedConditions` conditions. See this [documentation](http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp#explicit-and-implicit-waits-reference) and this [discussion](https://stackoverflow.com/questions/45712431/replace-implicit-wait-with-explicit-wait-selenium-webdriver-java/45715759#45715759) for more details. – undetected Selenium Aug 30 '17 at 10:20
  • I see, but don't understand why the same code isn't working with different versions. – plaidshirt Aug 30 '17 at 10:53
  • @plaidshirt There had been some changes in the core functionality of Selenium when we migrated from Selenium 2.x to Selenium 3.x. Hence we need to take care of the changes. If my Answer have catered to your Question please **`Accept`** the **`Answer`**. Thanks – undetected Selenium Aug 30 '17 at 11:00
1

Use implicit wait before URL like this:

driver.manage().timeouts().implicitlyWait(30, SECONDS);
driver.navigate().to(siteurl);

Use Explicit wait instead of fluent wait like below code:

WebDriverWait waitForElement = new WebDriverWait(driver, 5);
waitForElement.until(ExpectedConditions.elementToBeClickable(webpage.linput));
iamsankalp89
  • 4,607
  • 2
  • 15
  • 36