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
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 (ie 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.
A few words about Implicit Wait
:
ImplicitWait
as per the official documentation is to configure the WebDriver
instance ie 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
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.
Incase you need to wait for any particular state of any particular WebElement
, Selenium have provided the in-built ExplicitWait
ie WebDriverWait
where you can choose from 50 odd ExpectedConditions
conditions. See this documentation and this discussion for more details.
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));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.