硒问题在手风琴中寻找元素
Selenium Issues finding element in an accordian
我正在尝试单击手风琴元素内的报告。
我尝试了多种方法来识别元素,但没有任何效果。
使用 XPath 和 Id 我收到以下错误消息:
OpenQA.Selenium.ElementNotInteractableException: 'element not interactable'
这是我试过的代码。
static IWebDriver driver = new ChromeDriver();
static IWebElement element;
driver.FindElement(By.XPath("//*[@id=\"ContentPlaceHolder1_ReportCreator1_DataListReports_3_LinkButtonReport_0\"]")).Click();
driver.FindElement(By.Id("ContentPlaceHolder1_ReportCreator1_DataListReports_3_LinkButtonReport_0")).Click();
这是我要瞄准的手风琴内部的 HTML,
<a id="ContentPlaceHolder1_ReportCreator1_DataListReports_3_LinkButtonReport_0" class="ReportImg" href="javascript:__doPostBack ('ctl00$ContentPlaceHolder1$ReportCreator1$AccordionReportList_Pane_3_content$DataListReports$ctl00$LinkButtonReport','')">All Assessments</a>
交互时元素可能不可见尝试使用 WebDriverWait()
并等待 ElementToBeClickable()
和以下定位器。
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("ContentPlaceHolder1_ReportCreator1_DataListReports_3_LinkButtonReport_0"))).Click();
或者
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//a[text()='All Assessments']"))).Click();
我正在尝试单击手风琴元素内的报告。
我尝试了多种方法来识别元素,但没有任何效果。
使用 XPath 和 Id 我收到以下错误消息:
OpenQA.Selenium.ElementNotInteractableException: 'element not interactable'
这是我试过的代码。
static IWebDriver driver = new ChromeDriver();
static IWebElement element;
driver.FindElement(By.XPath("//*[@id=\"ContentPlaceHolder1_ReportCreator1_DataListReports_3_LinkButtonReport_0\"]")).Click();
driver.FindElement(By.Id("ContentPlaceHolder1_ReportCreator1_DataListReports_3_LinkButtonReport_0")).Click();
这是我要瞄准的手风琴内部的 HTML,
<a id="ContentPlaceHolder1_ReportCreator1_DataListReports_3_LinkButtonReport_0" class="ReportImg" href="javascript:__doPostBack ('ctl00$ContentPlaceHolder1$ReportCreator1$AccordionReportList_Pane_3_content$DataListReports$ctl00$LinkButtonReport','')">All Assessments</a>
交互时元素可能不可见尝试使用 WebDriverWait()
并等待 ElementToBeClickable()
和以下定位器。
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("ContentPlaceHolder1_ReportCreator1_DataListReports_3_LinkButtonReport_0"))).Click();
或者
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//a[text()='All Assessments']"))).Click();