C# 使用Selenium Chromedriver时无法定位元素';C里有什么#
我试图让我的程序点击一个按钮,但我收到错误 我的代码:C# 使用Selenium Chromedriver时无法定位元素';C里有什么#,c#,selenium,xpath,css-selectors,webdriverwait,checkbox,C#,Selenium,Xpath,Css Selectors,Webdriverwait,Checkbox,我试图让我的程序点击一个按钮,但我收到错误 我的代码: driver.FindElementById("couponsinc-gallery-selectall").Click(); 错误: An unhandled exception of type 'OpenQA.Selenium.NoSuchElementException' occurred in WebDriver.dll no such element: Unable to locate element: {&
driver.FindElementById("couponsinc-gallery-selectall").Click();
错误:
An unhandled exception of type 'OpenQA.Selenium.NoSuchElementException' occurred in WebDriver.dll
no such element: Unable to locate element: {"method":"css selector","selector":"#\couponsinc\-gallery\-selectall"}
以下是页面上按钮的代码:
<div class="selectall">
<input type="checkbox" class="selectall-chk" id="couponsinc-gallery-selectall">
<label for="couponsinc-gallery-selectall">Clip All</label>
</div>
全部剪辑
我也尝试过使用FindElementByClassName
,但没有任何效果。我做错了什么?以文本为剪辑的所有剪辑都是
,因此您必须:
- 使所需帧可用并切换到该帧
- 使所需元素可单击
- 您可以使用以下任一选项:
- 使用
:CSS\u选择器
((IJavaScriptExecutor)driver).ExecuteScript("return scrollBy(0, 800);"); new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.CssSelector("iframe[title='Coupons']")); new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("input.selectall-chk#couponsinc-gallery-selectall"))).Click();
- 使用
:XPATH
((IJavaScriptExecutor)driver).ExecuteScript("return scrollBy(0, 800);"); new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.XPath("//iframe[@title='Coupons']")); new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//input[@class='selectall-chk' and @id='couponsinc-gallery-selectall']"))).Click();
- 浏览器快照:
参考文献 您可以在以下内容中找到一些相关讨论: