C# 硒元素在手风琴中的发现

C# 硒元素在手风琴中的发现,c#,selenium,selenium-webdriver,webdriverwait,C#,Selenium,Selenium Webdriver,Webdriverwait,我试图点击一个手风琴元素中的报告 我尝试了各种方法来识别元素,但没有任何效果 使用XPath和Id,我得到以下错误消息: OpenQA.Selenium.ElementNotInteractivatableException:“元素不可交互” 这是我试过的代码 static IWebDriver driver = new ChromeDriver(); static IWebElement element; driver.FindElement(By.XPath("//*[@id=\

我试图点击一个手风琴元素中的报告

我尝试了各种方法来识别元素,但没有任何效果

使用XPath和Id,我得到以下错误消息:

OpenQA.Selenium.ElementNotInteractivatableException:“元素不可交互”

这是我试过的代码

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();


仔细检查您的定位器是否唯一。。。打开开发控制台并尝试
$$(“#ContentPlaceHolder1_ReportCreator1_DataListReports_3_LinkButtonReport_0”)
。它是否只返回一个元素?这似乎是一个疯狂的长定位器不唯一。。。但我以前见过这样的问题,页面上有2个或更多元素,而第一个元素不可见,等等。感谢Kunduk,这两个都有效。不过我有个小问题。“ExpectedConditions”下面有一条弯弯曲曲的线,上面写着“不推荐”。我可以将其标记为过时,但我希望您可能有一个解决方案?@Lars7:使用NuGet,搜索DotNetSeleniumExtras.WaitHelpers,并将该名称空间导入到您的类中。再次检查这个答案@Kundak谢谢,你一直都很好helpful@Lars7:很高兴能帮忙。
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); 
wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//a[text()='All Assessments']"))).Click();