Please comment the following code I found on YouTube. It checks whether an element is present at the time
public boolean isElementPresent(By locator)
{
driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
List<WebElement> list = driver.findElements(locator);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
if (list.size() == 0)
return false;
else
return list.get(0).isDisplayed();
}
It dynamically changes implicitlyWait in the method. In all Selenium resources are always stated that the implicitWait can be set only once in the test class. The code above is similar to some extent to the explicit wait since it adapts to different situations. What is your opinion about this code?
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/6dfe7778-fc49-4086-8b30-7f14812e3d66o%40googlegroups.com.
It seems a bit pointless. What opinions do you have?
On Fri, 12 Jun 2020 at 20:20, Vladimir B <vladimir...@gmail.com> wrote:
--Please comment the following code I found on YouTube. It checks whether an element is present at the time
public boolean isElementPresent(By locator) { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); List<WebElement> list = driver.findElements(locator); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); if (list.size() == 0) return false; else return list.get(0).isDisplayed(); }
It dynamically changes implicitlyWait in the method. In all Selenium resources are always stated that the implicitWait can be set only once in the test class. The code above is similar to some extent to the explicit wait since it adapts to different situations. What is your opinion about this code?
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to seleniu...@googlegroups.com.
1 public boolean isElementPresent(By locator)
2 {
3 driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
4 List<WebElement> list = driver.findElements(locator);
5 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
6 if (list.size() == 0)
7 return false;
8 else
9 return list.get(0).isDisplayed();
10 }
Line 3 sets implicit wait timeout to 0 seconds, presumably because line 4 is just trying to find if an element is present in the DOM at all.
Line 5 sets implicit wait timeout to 30 seconds, presumably because it was 30 seconds (setup in some place we can' see) before line 3 set it to 0 seconds.
Both line 3 and 5 set the implicit wait timeout for the session. What the documentation means is that an implicit wait is not specifically scoped to the function you use it in but the scope of the driver itself.
The reason I think it's a bit pointless is because I don't really like functions that make random changes like this. At the very least they're annoying to debug.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/0d16b232-fb5a-4c9f-bd10-6f12cdc427c9o%40googlegroups.com.
@BeforeEach
void setUp()
{
driver = new ChromeDriver();
}
@Test
void test1()
{
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
...
}
@Test
void test2()
{
...
}
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/0d16b232-fb5a-4c9f-bd10-6f12cdc427c9o%40googlegroups.com.