我是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)
但是无法找到元素错误.
我需要帮助解决这个问题.谢谢你的阅读.
如果你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)