【问题标题】:I am unable to use Selenium Explicit Wait if it contains jquery index如果它包含 jquery 索引,我将无法使用 Selenium Explicit Wait
【发布时间】:2019-09-05 10:46:14
【问题描述】:

我在 selenium webdriver 显式等待中使用 jquery index "eq(1)",但它不起作用。

如果我从代码中删除这个eq('" + Index + "'),那么它可以工作,但仅适用于第一个索引。这个你能帮我吗。谢谢

这是我正在尝试编写的代码,我必须使用索引。

var elementClickable = new WebDriverWait(driver, TimeSpan.FromSeconds(60)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("[data-uipath='" + uiPath + "'] :eq('" + Index + "')")));

【问题讨论】:

    标签: c# selenium selenium-webdriver webdriverwait


    【解决方案1】:

    您不能使用:eq(),它不是 Selenium 中的有效选择器。请改用:nth-child。记得给Index添加+1,:eq()使用基于0的索引,:nth-child()使用基于1的索引

    By.CssSelector("[data-uipath='" + uiPath + "']:nth-child(" + (Index + 1) +")")
    

    【讨论】:

    • 我想你的意思是By.CssSelector("[data-uipath='" + uiPath + "']:nth-child(" + 'Index + 1' + ")")
    • @AndreiSuvorkov 有",没有'
    【解决方案2】:

    尝试删除索引周围的引号,如下所示。它可能会起作用。

    var elementClickable = new WebDriverWait(driver, TimeSpan.FromSeconds(60)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("[data-uipath='" + uiPath + "'] :eq(" + Index + ")")));
    

    【讨论】:

      猜你喜欢
      • 2016-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-11
      • 1970-01-01
      • 2013-01-08
      相关资源
      最近更新 更多