Hi Raghav, thanks a lot for teaching. Can we store it in a String? I mean the whole line of code: driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); I want to put it in a variable say waitPlease, so that when i wanna put wait, i don't have to right all the line, but i just write waitPlease; or can we make a function out of it? so that we can just write waitPlease(); and then we don*t have to write the whole line? is it possible?
Syed Yes, you can store the whole line of code `driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));` in a String variable, or you can make a function out of it. **To store the wait code in a String variable:** ```java String waitPlease = "driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));"; ``` Then, you can use the `waitPlease` variable to wait for elements to be present on the page: ```java // Wait for the element with the ID "myElement" to be present on the page. WebElement element = driver.findElementById("myElement"); eval(waitPlease); element.click(); ``` **To make a function out of the wait code:** ```java public static void waitPlease() { driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); } ``` Then, you can call the `waitPlease()` function to wait for elements to be present on the page: ```java // Wait for the element with the ID "myElement" to be present on the page. WebElement element = driver.findElementById("myElement"); waitPlease(); element.click(); ``` **Which option should you use?** Both options are valid, but I recommend using the function option if you are going to be using the wait code multiple times in your test. This will make your code more readable and maintainable. Here are some additional tips for using waits in Selenium: * Use implicit waits sparingly. Implicit waits can slow down your tests, so it is best to only use them when necessary. * Use explicit waits to wait for specific conditions to be met. For example, you can use an explicit wait to wait for an element to be visible, clickable, or enabled. * Be careful not to overuse waits. Too many waits can make your tests slow and unreliable. I hope this helps
Your tech teaching style is really effective. I'm learning so much
Glad you think so!
That is a great playlist of teachings.
Thank you very much 🙏
You are very welcome Juaz
Thanks raghav , for explaining about different types of waits and explaining fluent wait difference also , thanks a ton !
Most welcome
Thank you for sharing another informative session.
Most welcome
another great tutorial! thank u so much Raghav from Ukraine!
Most welcome Ekaterina
Much awaited. ♥️
Thanks for looking forward Asha, next video will come soon
Very useful tutorial, thanks !
Most welcome
Awesome tutorial
Thanks Jannat
Thanks a lot
Most welcome
Thanks a lot Raghav. I hope you'll also cover the Bidi api part. Looking forward to it.
I will try Sudip
@@RaghavPal Thanks 😊
Hope so start soon..👍
:)
Good one Sir👏👏
Thanks
Thank you
Most welcome
Ragave sir can you make video on how we use JavaScript Executors along with Page Object Model. I tried lots of time but it not getting idea on it.
I will do Jayesh
Thank you ragav sir
Hi Raghav,
thanks a lot for teaching.
Can we store it in a String? I mean the whole line of code: driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
I want to put it in a variable say waitPlease, so that when i wanna put wait, i don't have to right all the line, but i just write waitPlease;
or can we make a function out of it? so that we can just write waitPlease(); and then we don*t have to write the whole line?
is it possible?
Syed
Yes, you can store the whole line of code `driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));` in a String variable, or you can make a function out of it.
**To store the wait code in a String variable:**
```java
String waitPlease = "driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));";
```
Then, you can use the `waitPlease` variable to wait for elements to be present on the page:
```java
// Wait for the element with the ID "myElement" to be present on the page.
WebElement element = driver.findElementById("myElement");
eval(waitPlease);
element.click();
```
**To make a function out of the wait code:**
```java
public static void waitPlease() {
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
}
```
Then, you can call the `waitPlease()` function to wait for elements to be present on the page:
```java
// Wait for the element with the ID "myElement" to be present on the page.
WebElement element = driver.findElementById("myElement");
waitPlease();
element.click();
```
**Which option should you use?**
Both options are valid, but I recommend using the function option if you are going to be using the wait code multiple times in your test. This will make your code more readable and maintainable.
Here are some additional tips for using waits in Selenium:
* Use implicit waits sparingly. Implicit waits can slow down your tests, so it is best to only use them when necessary.
* Use explicit waits to wait for specific conditions to be met. For example, you can use an explicit wait to wait for an element to be visible, clickable, or enabled.
* Be careful not to overuse waits. Too many waits can make your tests slow and unreliable.
I hope this helps
what's are the changes in wait statement for selenium 4 and 3?
Arpita
In Selenium 4, there are changes in the wait statements compared to Selenium 3. Here's a summary:
1. Implicit Wait:
- Selenium 3:
```java
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
```
- Selenium 4 (deprecated):
```java
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
```
2. Explicit Wait (WebDriverWait):
- Selenium 3:
```java
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".classlocator")));
```
- Selenium 4:
```java
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".classlocator")));
```
3. Fluent Wait:
- Selenium 3:
```java
Wait wait = new FluentWait(driver)
.withTimeout(30, TimeUnit.SECONDS)
.pollingEvery(5, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class);
```
- Selenium 4:
```java
Wait fluentWait = new FluentWait(driver)
.withTimeout(Duration.ofSeconds(30))
.pollingEvery(Duration.ofSeconds(5))
.ignoring(NoSuchElementException.class);
```
Remember to adapt your existing code to these changes when migrating to Selenium 4.
..
@@RaghavPal thank you so much Sir
Hello Mr. Raghav, would you guide me. How to change http port tp https port for Jenkins?
Hi Eko, not sure on this
@@RaghavPal alright thx Mr raghav, because i have problem here
If I find something useful will share with you
Ragav.
Is there anyway to convert .xlsb to .xlsx using Apache poi
Not sure Hari
don't mix explicit and implicit waits
Yes, or use them with the wait time calculated