我有按钮,在网页上,看起来像这样:硒返回IWebElement通过按钮上的文字
<button type="button" class="btn btn-primary btn xs-width-100" onclick="startScreening(0, 'A', 'UK');">Start Screening</button>`
此按钮有一个非常相似的结构,页面上的其他按钮。我正在尝试使用Selenium WebDriver
来查找此元素。我目前正在使用此:
return UFEElement<IWebElement>(FieldType.Link, By.XPath("//button[@class=\"btn btn-primary btn xs-width-100\"]"));
我不能class
找到,因为页面上的其他按钮具有相同的class
,我不能onclick
找到,因为根据该值的变化是以前的操作。
我试过By.XPath("//*[contains(text(), 'My Button')]")
和类似的方法,但它不起作用。
我得到一个错误: -
Error: An exception of type 'OpenQA.Selenium.NoSuchElementException' occurred in WebDriver.dll but was not handled in user code.
有另一种方式来找到这个元素?
这个定位器有什么问题'By.XPath(“// * [contains(text(),'Start Screening')]”)'??有什么异常吗? –
错误:'WebDriver.dll中发生类型'OpenQA.Selenium.NoSuchElementException'的异常,但未在用户代码中处理。 – Ross
你找帧/ iframe了吗?确保这个元素不在任何框架/ iframe中? –