简体   繁体   English

Chrome,Selenium C#中的WebDriverWait

[英]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" 我最近将WebDriver从Firefox更改为ChromeDriver,以前使用的等待步骤一直无法使用,直到元素可以进行交互为止”

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. 我现在经常会收到类似“元素在点(964,776)不可点击。其他元素会收到点击:”之类的错误,即使该元素在页面上可见。

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? 有没有一种方法可以告诉网络驱动程序等待某个元素可以与某个元素进行交互,或者更好地与我可以更改的任何设置进行交互,以让Selenium知道我正在使用Chrome,以便我的现有代码可以正常工作?

Latest version of Selenium C# Binding(2.46) provides a method to Expected Conditions named ElementToBeClickable . Selenium C#Binding(2.46)的最新版本提供了一种预期条件的方法,名为ElementToBeClickable Try that instead. 试试吧。 This is a very common issue with Chrome though. 不过,这是Chrome非常常见的问题。

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();

   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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