无法使用 C# 在 selenium webdriver 脚本中使用 XPath 定位元素

用户8356727

在我使用 selenium webdriver 的自动化脚本中,带有 id 的网页中的一些元素:

//*[@id="SalesTable_2_General_button"] 

这些都检测不到。我尝试了以下方法:

FindElement(By.XPath("//*[contains(@id,'_General_button')]"));
FindElement(By.XPath("//*[@id='SalesTable_2_General_button']"));

我无法获得任何其他独特的属性,如 @name、@title 等。请帮助我。

<button class="appBarTab-header allowFlyoutClickPropagation" id="SalesTable_12_General_button" aria-expanded="false" type="button" data-dyn-bind="&#10;        id: $data.Id + '_button',&#10;        keyDown: $data.keyDown,&#10;        enabled: $data.Enabled,&#10;        focusIn: $data.focusIn,&#10;        click: $data._headerClicked,&#10;        flyout: {&#10;            flyout: $('.appBar-flyout', $element.parentElement),&#10;            show: $data.FlyoutExpanded,           &#10;            at: 'manual',&#10;            openOnClick: false,&#10;            clickSubscriber: $data.flyoutClickSubscriber,&#10;            entranceAnimation: 'appBar-growHeight',&#10;            exitAnimation: $data.flyoutExitAnimation,&#10;            }">
        <span class="appBarTab-headerLabel allowFlyoutClickPropagation" data-dyn-bind="&#10;              text: $data.Label">General</span>
</button>

德班詹B

要将文本定位为General的元素,您可以使用以下代码行:

IWebElement element = wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//button[@class='appBarTab-header allowFlyoutClickPropagation' and starts-with(@id,'SalesTable_')]/span[@class='appBarTab-headerLabel allowFlyoutClickPropagation' and contains(.,'General')]")));

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Selenium Webdriver C# 无法使用有效的 XPath 表达式在 Chrome 中定位元素

无法在python中使用Selenium Webdriver定位元素

无法使用 Selenium WebDriver 在画布上定位元素

无法在 python 上使用 selenium webdriver 定位元素

使用Selenium和Python无法通过xpath定位元素

尽管 xPath 无法使用 Selenium Python 定位元素

使用父 selenium xpath 在 dom 中定位元素

使用Xpath定位元素

无法在python硒中使用Selenium Chrome WebDriver定位元素

即使元素 id 存在,也无法使用 selenium webdriver 定位元素

无法使用Xpath定位元素

无法使用 Selenium Python 定位元素

无法使用Selenium Python定位元素

无法使用 Selenium 定位元素

Selenium WebDriver:无法使用TinyMCE编辑器在iframe中定位元素

無法在 Selenium 中使用 Xpath 查找元素來定位元素方法?

Python中的Selenium显示无法使用xpath表达式定位元素

Selenium 无法定位元素,一个使用xpath 的搜索按钮

无法使用 Python Selenium fin_element_by_xpath 定位元素

没有这样的元素:无法使用Xpath在C#中定位元素

无法在xpath中使用和条件定位元素

无法在Appium中使用xpath定位元素

无法在Robot Framework中使用XPath定位元素

无法在xpath中使用和条件定位元素

无法在Selenium和Python中使用OR定位元素

Python Selenium没有这样的元素:移动到元素操作后无法使用xpath定位元素

Selenium Webdriver(Python)-无法在嵌套iframe中定位元素

如何通过Python使用Selenium WebDriver在iframe中定位元素

如何使用Selenium Python定位元素