mardi 17 octobre 2017

C# Selenium WebDriver wait for some elements to be fully loaded before going on

Here is what I would like to do via Selenium WebDriver :

  1. Go to http://ift.tt/2ifdJpx
  2. Click on a filter
  3. Click on the first Ad after filtering is done

What it does instead is clicking on the first Ad before filtering (the whole page is not reloaded for filtering, just the Ad list)

var url = "http://ift.tt/2ifdJpx";
RemoteWebDriver _driver = new FirefoxDriver();
_driver.Manage().Window.Maximize();
_driver.Navigate().GoToUrl(url);

_driver.FindElement(By.CssSelector("#jsFilterItems_2 > ul > li:nth-child(2) > div > label > input")).Click();
System.Threading.Thread.Sleep(3000);
_driver.FindElement(By.CssSelector("article > .box_product_item.art-div > .listview > .middle > h2")).Click();

The only way I found to make it work is to add a Thread.Sleep which is not the best solution. I also tried to manage timeouts but without success. Any suggestion?

Aucun commentaire:

Enregistrer un commentaire