0

please help me in understanding the following issue. please.

I have to get all links and check them later. I used the following code:

open(url);
List<String> links = new ArrayList<>();
for (SelenideElement link : $$("a"))
    links.add(link.attr("href"));

when I used this with Linux with these api version: Maven 3.1 Selenide v3.5 Selenium v2.53 Firefox v45.0.1 Then code can't take time enough to catch links from the page. Then I have to add driver wait before get links. I Add the following (which is conditional wait):

WebDriverWait waitLog = new WebDriverWait(WebDriverRunner.getWebDriver(), 20);
waitLog.until(ExpectedConditions.visibilityOf($(By.tagName(Selector))));

And it worked fine and I run it more than one time.

I got surprised when running it yesterday, it didn't work and can't get time enough to get links!

So I replace the conditional wait with implicit wait, and add the following:

WebDriverRunner.getWebDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);    

Now it is working fine.

  • What happened?

  • What is this thing make it work sometimes and sometimes can't work?

  • How to return back to the conditional wait with keeping the code working well?

So how to recover this problem? and prevent this problem from happens in the future.

Hana90
  • 943
  • 5
  • 17
  • 37

1 Answers1

0

There might be some delay in loading the url for the second time. Please try increasing the delay time for conditional wait. The main difference between explicit and implicit wait is as follows.

Explicit or conditional wait stops the WebDriver for the specified amount of time, till the mentioned element is available. Whereas implicit wait will skip execution of WebDriver for specified amount of time, for every element which is not found on the page.

Hope this helps.

k.s. Karthik
  • 731
  • 6
  • 16