• <tfoot id='XVSs7'></tfoot>
  • <i id='XVSs7'><tr id='XVSs7'><dt id='XVSs7'><q id='XVSs7'><span id='XVSs7'><b id='XVSs7'><form id='XVSs7'><ins id='XVSs7'></ins><ul id='XVSs7'></ul><sub id='XVSs7'></sub></form><legend id='XVSs7'></legend><bdo id='XVSs7'><pre id='XVSs7'><center id='XVSs7'></center></pre></bdo></b><th id='XVSs7'></th></span></q></dt></tr></i><div id='XVSs7'><tfoot id='XVSs7'></tfoot><dl id='XVSs7'><fieldset id='XVSs7'></fieldset></dl></div>

    1. <legend id='XVSs7'><style id='XVSs7'><dir id='XVSs7'><q id='XVSs7'></q></dir></style></legend>

      <small id='XVSs7'></small><noframes id='XVSs7'>

        • <bdo id='XVSs7'></bdo><ul id='XVSs7'></ul>
      1. 即使元素存在,ExpectedConditions.ElementIsVisible 也会返回 TimeoutExcep

        ExpectedConditions.ElementIsVisible returns TimeoutException even when element is present(即使元素存在,ExpectedConditions.ElementIsVisible 也会返回 TimeoutException)
      2. <legend id='4Ito9'><style id='4Ito9'><dir id='4Ito9'><q id='4Ito9'></q></dir></style></legend>
          <tbody id='4Ito9'></tbody>
        <i id='4Ito9'><tr id='4Ito9'><dt id='4Ito9'><q id='4Ito9'><span id='4Ito9'><b id='4Ito9'><form id='4Ito9'><ins id='4Ito9'></ins><ul id='4Ito9'></ul><sub id='4Ito9'></sub></form><legend id='4Ito9'></legend><bdo id='4Ito9'><pre id='4Ito9'><center id='4Ito9'></center></pre></bdo></b><th id='4Ito9'></th></span></q></dt></tr></i><div id='4Ito9'><tfoot id='4Ito9'></tfoot><dl id='4Ito9'><fieldset id='4Ito9'></fieldset></dl></div>

              <tfoot id='4Ito9'></tfoot>

              <small id='4Ito9'></small><noframes id='4Ito9'>

              • <bdo id='4Ito9'></bdo><ul id='4Ito9'></ul>
                  本文介绍了即使元素存在,ExpectedConditions.ElementIsVisible 也会返回 TimeoutException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 Selenium ChromeDriver v2.40,Chrome 版本 67.

                  I'm using Selenium ChromeDriver v2.40, Chrome version 67.

                  var driver = Browser.GetChromeDriver();          
                  driver.Navigate().GoToUrl(url);
                  var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
                  var abc=driver.FindElement(By.XPath("//*[@id='pdp-size-select']"));
                  var aaa=wait.Until(d => d.FindElement(By.XPath("//*[@id='pdp-size-select']")));
                  abc.Click(); // failed because elementisnotvisible
                  

                  以上两个findelement工作正常,可以取值但是不能点击因为元素不可见

                  the above two findelement works fine, can get value but cannot click because the element is not visible

                  所以我继续尝试 ExpectedConditions,但没有运气:

                  so i go on to try ExpectedConditions, and no luck with this:

                  wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("//*[@id='pdp-size-select']")));
                  

                  以上代码返回:

                  OpenQA.Selenium.WebDriverTimeoutException: 'Timed out after 10 seconds'
                  

                  它与 Chrome v67 是否存在向后兼容性问题?

                  Does it have any backward compatibility issues with Chrome v67?

                  推荐答案

                  根据错误 elementisnotvisible 似乎你已经很接近了.当您尝试在元素上调用 Click() 时向前推进,因此将 ExpectedConditions 替换为 ElementIsVisible() 你需要使用 ElementToBeClickable()如下:

                  As per the error elementisnotvisible seems you are pretty close. Moving forward as you are trying to invoke Click() on the element, so instead of ExpectedConditions as ElementIsVisible() you need to use ElementToBeClickable() as follows:

                  new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.XPath("//*[@id='pdp-size-select']"))).Click();
                  

                  没有对 SeleniumExtrasWaitHelpers 的任何引用,代码行将是:

                  With out any reference to SeleniumExtras and WaitHelpers the line of code will be:

                  new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//*[@id='pdp-size-select']"))).Click();
                  

                  注意:正如您提到的,您使用的是 Chrome v67.x,请确保您使用的是 ChromeDriver v2.40(但不是 ChromeDriver v2.4)

                  Note: As you mentioned you are using Chrome v67.x ensure that you are using ChromeDriver v2.40 (but not ChromeDriver v2.4)

                  进一步调试,您似乎拥有 定位器策略经过调整,准确识别 HTML DOM.所以你需要构造一个唯一的定位器来识别并点击所需的元素,如下所示:

                  Debugging further it seems the Locator Strategy you have adapted, identifies exactly two (2) elements within the HTML DOM. So you need to construct a unique locator to identify and click the desired element as follows:

                  new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//a[@data-track-action='Product-Page']//following::select[@id='pdp-size-select']"))).Click();
                  

                  注意:所需元素是 select 元素,如果您希望与 <select> 元素按 最佳实践您需要使用 SelectElement 类来自 OpenQA.Selenium.Support.UI 命名空间.

                  Note: The desired element is a select element and if you desire to interect with the <select> element as per best practices you need to use the SelectElement Class from OpenQA.Selenium.Support.UI Namespace.

                  这篇关于即使元素存在,ExpectedConditions.ElementIsVisible 也会返回 TimeoutException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  C# namespace alias - what#39;s the point?(C# 命名空间别名 - 有什么意义?)
                  Using Xpath With Default Namespace in C#(在 C# 中使用具有默认命名空间的 Xpath)
                  Generating an EDMX from a DB2 Database(从 DB2 数据库生成 EDMX)
                  IBM .NET Data Provider Connection String issue with Library List(库列表的 IBM .NET 数据提供程序连接字符串问题)
                  .NET DB2 OLEDB pre-requisites(.NET DB2 OLEDB 先决条件)
                  Referring to Code in IBM.Data.DB2 makes that Assembly Unavailable to the rest of my Solution(引用 IBM.Data.DB2 中的代码使该程序集对我的解决方案的其余部分不可用)

                  <legend id='OWRE5'><style id='OWRE5'><dir id='OWRE5'><q id='OWRE5'></q></dir></style></legend>
                    <bdo id='OWRE5'></bdo><ul id='OWRE5'></ul>
                    <tfoot id='OWRE5'></tfoot>

                        1. <small id='OWRE5'></small><noframes id='OWRE5'>

                              <tbody id='OWRE5'></tbody>
                          1. <i id='OWRE5'><tr id='OWRE5'><dt id='OWRE5'><q id='OWRE5'><span id='OWRE5'><b id='OWRE5'><form id='OWRE5'><ins id='OWRE5'></ins><ul id='OWRE5'></ul><sub id='OWRE5'></sub></form><legend id='OWRE5'></legend><bdo id='OWRE5'><pre id='OWRE5'><center id='OWRE5'></center></pre></bdo></b><th id='OWRE5'></th></span></q></dt></tr></i><div id='OWRE5'><tfoot id='OWRE5'></tfoot><dl id='OWRE5'><fieldset id='OWRE5'></fieldset></dl></div>