简体   繁体   中英

WebDriverWait in Chrome, Selenium C#

I have recently changed my WebDriver from Firefox to ChromeDriver and the wait steps I previously used to wait until an element could be interacted with no longer works"

WebDriverWait w = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); w.IgnoreExceptionTypes(typeof(StaleElementReferenceException), typeof(InvalidElementStateException)); w.Until(ExpectedConditions.ElementExists(By.Id("formSubmit")));

I now often get errors like "Element is not clickable at point (964, 776). Other element would receive the click: " for example, even though the element is visible on the page.

Is there a way of telling the webdriver to wait until an element can be interacted with, or better, any settings that I could change to let Selenium know that I'm using Chrome so that my existing code works?

Latest version of Selenium C# Binding(2.46) provides a method to Expected Conditions named ElementToBeClickable . Try that instead. This is a very common issue with Chrome though.

there is more than way this is my fav

try{
   //for example
           site.FindElement(By.Id("ctl00_ContentPlaceHolderBody_drp_City")).Click();

   }catch{

  Thread.Sleep(Time in sec);
           site.FindElement(By.Id("ctl00_ContentPlaceHolderBody_drp_City")).Click();

   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM