在我使用 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=" id: $data.Id + '_button', keyDown: $data.keyDown, enabled: $data.Enabled, focusIn: $data.focusIn, click: $data._headerClicked, flyout: { flyout: $('.appBar-flyout', $element.parentElement), show: $data.FlyoutExpanded, at: 'manual', openOnClick: false, clickSubscriber: $data.flyoutClickSubscriber, entranceAnimation: 'appBar-growHeight', exitAnimation: $data.flyoutExitAnimation, }">
<span class="appBarTab-headerLabel allowFlyoutClickPropagation" data-dyn-bind=" text: $data.Label">General</span>
</button>
要将文本定位为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] 删除。
我来说两句