Hi Wilson, you can read this stackoverflow.com/questions/40753321/fluent-wait-vs-webdriver-wait stackoverflow.com/questions/19908296/fluent-wait-and-webdriver-wait-differences
Hello sir , I have one condition in a portal where there is a random allocation , allocation happens after random interval time like 2 sec , 2 min , 2 hour. So I have to automate in a way whenever the allocation will happened it should auto accept . Any suggestion for making this script ?
"withTimeout(10, TimeUnit.Seconds)" and PollingEvery(2, TimeUnit.Seconds)" getting error that it is deprecated after Selenium v3.11.0. Using withTimeout(Duration.ofSeconds(10)) and pollingEvery(Duration.ofMillis(500)) will work now. Import Java.time.Duration
Hi Raghav, Which version of selenium are you using? I'm getting methods depreciated warning for version 3.14.0. I used 2.53.0 but the browser is closing very soon.
Wait wait = new FluentWait(driver) .withTimeout(30, SECONDS) .pollingEvery(5, SECONDS) .ignoring(NoSuchElementException.class); I got error here as well It didn't work saying WebDriverWait deprecated in Selenium 4.0.0-alpha-3. as I am using selenium-java version 4.0.0-alpha-5 Later I found out that Wait wait = new FluentWait(driver) .withTimeout(Duration.ofSeconds(30)) .pollingEvery(Duration.ofSeconds(5)) .ignoring(NoSuchElementException.class); There is change in syntax n it worked for me Hope this works for someone Thanks in advance Hima
If you write Flue and hover over, do you get option for FluentWait, then right click again on that option, you will get the documentation Else copy it from documentation page as shown.
Hi Raghav, I am getting the following error with FluentWait, "The type FluentWait is not generic; it cannot be parameterized with arguments " and I am selenium 3.12. Can you please advise. Thank you in advance.
@@RaghavPal from 7:10 to 7:50 , you selected a link from page 2 and you created a webelement for that.. But ur driver initially refers to page 1, how u r able to access elm of page 2.. after 7:50 u implemented fluent wait..
Wait wait = new FluentWait(driver) .withTimeout(5,TimeUnit.SECONDS) .pollingEvery(5,TimeUnit.SECONDS) .ignoring(NoSuchElementException.class); WebElement foo = wait.until(new Function() { public WebElement apply(WebDriver driver) { return driver.findElement(By.id("foo")); } }); Error is The method withTimeout(Duration) in the type FluentWait is not applicable for the arguments (int, TimeUnit) please Help
The original parameters for withTimeout() & pollingEvery() have been deprecated (changed and removed).These each now only take 1 parameter, which is a unit of time. Below is a sample of currently working code (without the warnings): Wait wait = new FluentWait(driver) .withTimeout(Duration.ofSeconds(30)) .pollingEvery(Duration.ofMillis(500)) .ignoring(NoSuchElementException.class);
These 2 lines are not working in selenium 4.11.0 WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(10)); FluentWait wait = new FluentWait(driver).withTimeout(Duration.ofSeconds(35)).pollingEvery(Duration.ofSeconds(10)); and also, wait.until(ExpectedConditions.visibilityOf(e)); Can anyone help me to handle this? Please
Revathi Yes, the `WebDriverWait` and `FluentWait` classes are deprecated in Selenium 4.11.0. You should use the `Wait` class instead. The `Wait` class has a constructor that takes a `Duration` object as its argument. The `Duration` object specifies the amount of time to wait for the condition to be met. For example, the following code creates a `Wait` object that will wait for 10 seconds for the element to be visible: ``` Wait wait = new Wait(driver, Duration.ofSeconds(10)); ``` The `wait.until()` method is also deprecated in Selenium 4.11.0. You should use the `until()` method instead. The `until()` method takes a `Function` object as its argument. The `Function` object specifies the condition that you want to wait for. For example, the following code waits for the element to be visible: ``` wait.until(ExpectedConditions.visibilityOf(e)); ``` Here is the updated code that you can use: ``` Wait wait = new Wait(driver, Duration.ofSeconds(10)); wait.until(ExpectedConditions.visibilityOf(e)); ``` I hope this helps
Hi sir, I cleared that Wait issue But another issue came while running the script [INFO] --- maven-compiler-plugin:3.11.0:testCompile (default-testCompile) @ Aim --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-surefire-plugin:3.0.0-M5:test (default-test) @ Aim --- [INFO] [INFO] ------------------------------------------------------- [INFO] T E S T S [INFO] ------------------------------------------------------- SLF4J: No SLF4J providers were found. SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See www.slf4j.org/codes.html#noProviders for further details. null com.google.inject.ProvisionException: Unable to provision, see the following errors: 1) [Guice/ErrorInjectingConstructor]: NoClassDefFoundError: org/openqa/selenium/interactions/HasInputDevices at WebdriverCloseBrowser.(WebdriverCloseBrowser.java:22) while locating WebdriverCloseBrowser at WebDriverModule.configure(WebDriverModule.java:20) while locating CloseBrowser Learn more: github.com/google/guice/wiki/ERROR_INJECTING_CONSTRUCTOR 1 error ====================== Full classname legend: ====================== CloseBrowser: "net.thucydides.core.webdriver.CloseBrowser" WebDriverModule: "net.thucydides.core.guice.webdriver.WebDriverModule" WebdriverCloseBrowser: "net.thucydides.core.webdriver.WebdriverCloseBrowser" ======================== End of classname legend: ======================== I checked in my script whether I am using the HasInputDevice. But I didn't found anything. I think it is indirectly using HasInputDevice. I know this method is deprecated in selenium 4.11.0 but I don't know how to solve?
thank you brother a always watch your tutorials.
Most welcome
Thanks this helped me so much
You're welcome Sekhar
Thanks it helped me👍
Glad it helped
Sir @15:48, if u don't click on manually on page 2 , Is our script automatically goto page 2 and click that required link🤔???
Is it, okay, I did not check that.
you can scroll down using javascriptexecutor and click on page 2 and then search for that link
What is difference between WebDriverWait and FluentWait ?
I feel WebDriverWait does same task with less lines of code.
Hi Wilson, you can read this
stackoverflow.com/questions/40753321/fluent-wait-vs-webdriver-wait
stackoverflow.com/questions/19908296/fluent-wait-and-webdriver-wait-differences
Hello sir , I have one condition in a portal where there is a random allocation , allocation happens after random interval time like 2 sec , 2 min , 2 hour. So I have to automate in a way whenever the allocation will happened it should auto accept .
Any suggestion for making this script ?
Hi Milind, I will need to check and study the scenario
@@RaghavPal Hello Sir , Thanks for your response , I have achieved the result ,
@@milindprabhakarshirsat1614 I am stuck in a similar situation please tell me how you achieved
Hi Raghav could you explain how to write fluent wait code in typescript?
I will create a session
In Selenium 4.0, we have to use "Java.time.duration", so the wait method would be .withTimeOut(Duration.ofSeconds(30))
Yes, thanks for adding
WHO IS YOUR TRAINER??
I just try on my own taking help from online resources
superb
Thanks Baji
"withTimeout(10, TimeUnit.Seconds)" and PollingEvery(2, TimeUnit.Seconds)" getting error that it is deprecated after Selenium v3.11.0. Using withTimeout(Duration.ofSeconds(10)) and pollingEvery(Duration.ofMillis(500)) will work now. Import Java.time.Duration
Hi Rahul, thanks for the update
@@RaghavPal Thank you Raghav... Learning a Lot from you🙏
Function and apply are keywords?
these are functions Rajini
Hi Raghav,
Which version of selenium are you using?
I'm getting methods depreciated warning for version 3.14.0.
I used 2.53.0 but the browser is closing very soon.
I used 3.4.0
@@RaghavPal I solved the depreciated warning issue but the browser is closing fast ..its not waiting for the time mentioned
Hi Zameer, what was the solution. Do you have any logs for this new issue.
Wait wait = new FluentWait(driver)
.withTimeout(30, SECONDS)
.pollingEvery(5, SECONDS)
.ignoring(NoSuchElementException.class);
I got error here as well
It didn't work saying WebDriverWait deprecated in Selenium 4.0.0-alpha-3. as I am using selenium-java version 4.0.0-alpha-5
Later I found out that
Wait wait = new FluentWait(driver)
.withTimeout(Duration.ofSeconds(30))
.pollingEvery(Duration.ofSeconds(5))
.ignoring(NoSuchElementException.class);
There is change in syntax n it worked for me
Hope this works for someone
Thanks in advance
Hima
Hi Hima, Thanks for adding this to help others
What is the problem if we use click
.rether than sendkeys.return. can you plz.explain
Thanks
Click will throw exception as that button is overlap by auto suggestion list , that's why we are using sendkeys
That's right, thanks Azhar
Some times I can't find button 'btnK' and use 'sendKey' only 'click' is working. Does anybody know why?
How you getting auto suggestion of code in eclipse, I am not getting in auto suggestion,if I am moving my mouse to those classes and methods.
If you write Flue and hover over, do you get option for FluentWait, then right click again on that option, you will get the documentation
Else copy it from documentation page as shown.
In want to apply fluent wait irrespective of all elements... how to achieve that??
Hi Mani, what exactly you mean by irrespective of all elements. This can help - www.techbeamers.com/webdriver-fluent-wait-command-examples/
Hi Raghav, I am getting the following error with FluentWait, "The type FluentWait is not generic; it cannot be parameterized with arguments " and I am selenium 3.12. Can you please advise. Thank you in advance.
Hi, have you imported Fluent Wait, Pls recheck and also refer in the video - ua-cam.com/video/iUQIL2VsHIk/v-deo.html
i am also getting the same error. import org.openqa.selenium.support.ui.*; - imported this package already. please suggest asap.
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.*;
import com.google.common.base.Function;
public class FluentWait {
public static void main(String[] args) throws Exception {
test();
}
public static void test() throws Exception
{
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Prakash\\eclipse-workspace\\SeleniumTrainings\\ExeFiles\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
//driver.manage().window().maximize();
driver.get("www.google.com");
driver.findElement(By.name("q")).sendKeys("selenium");
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(By.name("btnK")).sendKeys(Keys.ENTER);
//driver.findElement(By.className("LC20lb DKV0Md")).click();
Wait wait = new FluentWait(driver)
.withTimeout(30, TimeUnit.SECONDS)
.pollingEvery(5, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class);
WebElement foo = wait.until(new Function() {
public WebElement apply(WebDriver driver) {
WebElement linkelement = driver.findElement(By.className("LC20lb DKV0Md"));
if(linkelement.isEnabled()) {
System.out.println("found");}
return linkelement;
}
});
foo.click();
}
}
This is my script. please suggest.
How does he is able to click on a link of page 2 from page 1?
Hi Virat, pls point the time in the video so I can check
@@RaghavPal from 7:10 to 7:50 , you selected a link from page 2 and you created a webelement for that.. But ur driver initially refers to page 1, how u r able to access elm of page 2.. after 7:50 u implemented fluent wait..
Hi Virat, if you check at 15:45, I have manually clicked on page 2 link. This was just to show the working of fluent wait
you should have explained wait.until in detail. that was the most important part.
Sure. I will check on this and improve
This reminds me CompletableFeature from Java threads :D I find it similar in some ways.
thanks for adding
Wait wait = new FluentWait(driver)
.withTimeout(5,TimeUnit.SECONDS)
.pollingEvery(5,TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class);
WebElement foo = wait.until(new Function() {
public WebElement apply(WebDriver driver) {
return driver.findElement(By.id("foo"));
}
});
Error is
The method withTimeout(Duration) in the type FluentWait is not applicable for the arguments (int, TimeUnit)
please Help
Hi Ashwini, what are your imports. Try
import java.time.Duration;
The original parameters for withTimeout() & pollingEvery() have been deprecated (changed and removed).These each now only take 1 parameter, which is a unit of time.
Below is a sample of currently working code (without the warnings):
Wait wait = new FluentWait(driver)
.withTimeout(Duration.ofSeconds(30))
.pollingEvery(Duration.ofMillis(500))
.ignoring(NoSuchElementException.class);
These 2 lines are not working in selenium 4.11.0
WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(10));
FluentWait wait = new FluentWait(driver).withTimeout(Duration.ofSeconds(35)).pollingEvery(Duration.ofSeconds(10));
and also,
wait.until(ExpectedConditions.visibilityOf(e));
Can anyone help me to handle this? Please
Revathi
Yes, the `WebDriverWait` and `FluentWait` classes are deprecated in Selenium 4.11.0. You should use the `Wait` class instead.
The `Wait` class has a constructor that takes a `Duration` object as its argument. The `Duration` object specifies the amount of time to wait for the condition to be met.
For example, the following code creates a `Wait` object that will wait for 10 seconds for the element to be visible:
```
Wait wait = new Wait(driver, Duration.ofSeconds(10));
```
The `wait.until()` method is also deprecated in Selenium 4.11.0. You should use the `until()` method instead.
The `until()` method takes a `Function` object as its argument. The `Function` object specifies the condition that you want to wait for.
For example, the following code waits for the element to be visible:
```
wait.until(ExpectedConditions.visibilityOf(e));
```
Here is the updated code that you can use:
```
Wait wait = new Wait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.visibilityOf(e));
```
I hope this helps
@@RaghavPal public void waitforvisiblityofelement(String element) {
WebElement e = getelement(element);
try {
Wait wait = new Wait(driver, Duration.ofSeconds(10));
wait.withTimeout(Duration.ofSeconds(35));
wait.pollingEvery(Duration.ofSeconds(10));
wait.ignoring(NoSuchElementException.class);
wait.ignoring(ElementNotVisibleException.class);
wait.ignoring(StaleElementReferenceException.class);
wait.ignoring(NoSuchFrameException.class);
wait.ignoring(TimeoutException.class);
wait.ignoring(NoAlertPresentException.class)
wait.ignoring(NoSuchWindowException.class);
wait.until(ExpectedConditions.visibilityOf(e));
wait.until(ExpectedConditions.elementToBeClickable(e));
wait.until(ExpectedConditions.visibilityOfAllElements(e));
wait.until(ExpectedConditions.alertIsPresent());
wait.until(ExpectedConditions.elementSelectionStateToBe(e, true));
wait.until(ExpectedConditions.elementToBeSelected(e));
// Add more conditions as needed
} catch (Exception ex) {
ex.printStackTrace();
}
}
No sir, I can't able to import the above Wait and ExpectedConditions
Using selenium 4.11.0 only
Can check and try some online examples
@@RaghavPal Okay
Hi sir,
I cleared that Wait issue
But another issue came while running the script
[INFO] --- maven-compiler-plugin:3.11.0:testCompile (default-testCompile) @ Aim ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M5:test (default-test) @ Aim ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See www.slf4j.org/codes.html#noProviders for further details.
null
com.google.inject.ProvisionException:
Unable to provision, see the following errors:
1) [Guice/ErrorInjectingConstructor]: NoClassDefFoundError: org/openqa/selenium/interactions/HasInputDevices
at WebdriverCloseBrowser.(WebdriverCloseBrowser.java:22)
while locating WebdriverCloseBrowser
at WebDriverModule.configure(WebDriverModule.java:20)
while locating CloseBrowser
Learn more:
github.com/google/guice/wiki/ERROR_INJECTING_CONSTRUCTOR
1 error
======================
Full classname legend:
======================
CloseBrowser: "net.thucydides.core.webdriver.CloseBrowser"
WebDriverModule: "net.thucydides.core.guice.webdriver.WebDriverModule"
WebdriverCloseBrowser: "net.thucydides.core.webdriver.WebdriverCloseBrowser"
========================
End of classname legend:
========================
I checked in my script whether I am using the HasInputDevice. But I didn't found anything. I think it is indirectly using HasInputDevice. I know this method is deprecated in selenium 4.11.0 but I don't know how to solve?
Its really confusing to inspect current google results. unable to click on anything automatically with code, need to understand and work more
Was able to find by xpath and click on it
:)