Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#Selenium驱动程序-通过文本获取所有元素 私有IWebDriver-webDriver; [设置] 公共作废设置() { webDriver=新的FirefoxDriver(); webDriver.Navigate().GoToUrl(“https://localhost:44311/"); } [测试] public void按钮count\u IsCorrect\u IsTrue() { var buttons=webDriver.FindElement(…); ... }_C#_Asp.net_Selenium_Automation - Fatal编程技术网

C#Selenium驱动程序-通过文本获取所有元素 私有IWebDriver-webDriver; [设置] 公共作废设置() { webDriver=新的FirefoxDriver(); webDriver.Navigate().GoToUrl(“https://localhost:44311/"); } [测试] public void按钮count\u IsCorrect\u IsTrue() { var buttons=webDriver.FindElement(…); ... }

C#Selenium驱动程序-通过文本获取所有元素 私有IWebDriver-webDriver; [设置] 公共作废设置() { webDriver=新的FirefoxDriver(); webDriver.Navigate().GoToUrl(“https://localhost:44311/"); } [测试] public void按钮count\u IsCorrect\u IsTrue() { var buttons=webDriver.FindElement(…); ... },c#,asp.net,selenium,automation,C#,Asp.net,Selenium,Automation,简单场景-网站包含动态创建的按钮。我想确保按钮的数量与预期的相同 通过XPath捕获它很容易,但XPath会导致某些元素,这里我们希望捕获多个动态创建的元素,但每个元素看起来如下所示: 详细信息 唯一的区别是href的引导位置,我跳过了课程,因为它们在这里并不重要 结论是,明智的做法是搜索所有包含字符串详细信息的。现在的问题是,如何在C#driver中实现这一点。您可以将findElements与xpath结合使用来查找元素列表: List<WebElement> elementN

简单场景-网站包含动态创建的按钮。我想确保按钮的数量与预期的相同

通过XPath捕获它很容易,但XPath会导致某些元素,这里我们希望捕获多个动态创建的元素,但每个元素看起来如下所示:

详细信息
唯一的区别是
href
的引导位置,我跳过了课程,因为它们在这里并不重要


结论是,明智的做法是搜索所有包含字符串
详细信息的
。现在的问题是,如何在C#driver中实现这一点。

您可以将
findElements
与xpath结合使用来查找元素列表:

List<WebElement> elementName = driver.FindElements(By.XPath("//a[contains(text(),'Details')]"));
List elementName=driver.FindElements(By.XPath(“//a[contains(text(),'Details')]”);

列表包含0个元素,这不是真的。添加等待:
WebDriverWait wait=new WebDriverWait(驱动程序,TimeSpan.FromSeconds(5));IWebElement elementName=wait.Until(ExpectedConditions.ElementIsVisible(By.XPath(//a[contains(text(),'Details')]))
什么是
预期条件
?请查看此处的等待解决方案,您是否提供了足够的等待来正确加载页面?如果您仍然获得
列表。计数
0,然后检查iframe中是否存在元素?@KunduK我认为应该可以,因为
By.LinkText
工作正常。但我仍然想知道如何操作如果要搜索
div
或其他任何内容,请解决此问题。