0

on this link https://www.scoreboard.com/en/soccer/england/premier-league/results/ I click on button(link) "Show more matches" with Selenium and I want wait until function loads results. How to do it using selenium respectively this is my code

driver.findElement(By.linkText("Zobrazit více zápasů")).click();           
Thread.sleep(1000);

and replace Thread.sleep(1000) with something that will wait until the function is over.

Martin
  • 27
  • 4
  • Possible duplicate of [How can I ask the Selenium-WebDriver to wait for few seconds in Java?](https://stackoverflow.com/questions/12858972/how-can-i-ask-the-selenium-webdriver-to-wait-for-few-seconds-in-java) – George Z. Mar 17 '19 at 22:56
  • You can use `wait.until(ExpectedConditions.visibilityOfElementLocated(locator));` – Rmahajan Mar 17 '19 at 23:21
  • I used `new WebDriverWait(driver,15).until(ExpectedConditions.visibilityOf(driver.findElement(By.linkText("Show more matches"))));` and it works, but sometimes it doesn´t. I explain it. When it click on button "Show more matches" I need it to wait for the results to load and click the button again until all the results appear on the page. This means from the first to the last round played. And sometimes it doesn´t load all rounds. – Martin Mar 18 '19 at 00:37
  • And I don´t know where is the problem. It works in 9 out of 10 cases correctly. – Martin Mar 18 '19 at 00:41
  • I think `ExpectedConditions.elementToBeClickable` should work better than `visibilityOf` for your case. – Kamal Mar 18 '19 at 01:33
  • It didn´t help. It didn´t work 100%. I don´t have any ideas where problem is. – Martin Mar 18 '19 at 01:54
  • What am I doing wrong? `while(true) { try { driver.findElement(By.linkText("Show more matches")).click(); counter++; new WebDriverWait(driver,15).until(ExpectedConditions.elementToBeClickable(By.linkText("Show more matches"))); } catch (Exception e) { break; } }` – Martin Mar 18 '19 at 01:57
  • What exactly do you mean by `How to do it using selenium respectively`? – undetected Selenium Mar 18 '19 at 05:07
  • I was thinking of using something of selenium. For example WebdriverWait. Is that already understandable? – Martin Mar 18 '19 at 14:12
  • But it doesn´t matter, I found the problem. The link is not clickable in that moment, because there is some layout and i didn´t see it. Thanks everyone for your help. I appreciate it. – Martin Mar 18 '19 at 14:43

0 Answers0