[英]Getting Selenium to click a radio button with no ID or name
我正在尝试设置页面的Selenium测试,但无法点击单选按钮
我正在尝试使用IWebDriver xpath方法
<fieldset class="radio-button-list">
<label >
<span class="className">Text1</span>
<input type="radio" value="Button1">
</label>
<label>
<span class="className">Text2</span>
<input type="radio" value="Button2">
</label>
</fieldset>
这就是我正在使用的......
driver.FindElement(By.XPath("//button[contains(text(),'Text2')]")).Click();
我希望它点击单选按钮,但我收到此错误:
OpenQA.Selenium.NoSuchElementException: 'no such element: Unable to locate element: {"method":"xpath","selector":"//button[contains(text(),'Text2')]"}
试试这个:
driver.FindElement(By.XPath(".//fieldset[@class='radio-button-list']/label[2]/input[@value='Button2']")).Click();
我认为发生的事情是你的页面上没有'button'元素,因此'NoSuchElementException'。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.