选择selenium中的单选按钮c#

8be*_*rry 2 c# selenium xpath

我是XPath和CssSelector的新手.

下面是目标html源.

<input value="1" name="uji.model.611876.button" type="radio"></input>
Run Code Online (Sandbox Code Playgroud)

611876是一个随机数.

我尝试了代码:

driver.FindElement(By.Id("//input[@value=\"1\"]")).Click();
Run Code Online (Sandbox Code Playgroud)

driver.FindElement(By.Id("//input[@value='1']")).Click();
Run Code Online (Sandbox Code Playgroud)

但是无法找到元素错误.

我需要帮助解决这个问题.谢谢你的阅读.

And*_*son 5

如果你ElementNotVisibleException试着等待一段时间直到目标input可见:

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(15));
IWebElement element = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//input[starts-with(@name, \"uji.model.\")][@type=\"radio\"]")));
element.Click();
Run Code Online (Sandbox Code Playgroud)