Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.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/8/selenium/4.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#_C#_Selenium_Svg_Xpath_Selenium Chromedriver - Fatal编程技术网

查找第页上的文本,如果未找到,请转到下一页。硒C#

查找第页上的文本,如果未找到,请转到下一页。硒C#,c#,selenium,svg,xpath,selenium-chromedriver,C#,Selenium,Svg,Xpath,Selenium Chromedriver,我想用selenium和NUnit测试网页上是否有特定的文本。 如果文本存在,则测试应通过。 如果文本不在当前页面上,则应单击“下一页”按钮,然后再次搜索新页面 现在我得到了这个: IWebDriver webDriver = new ChromeDriver(); webDriver.Navigate().GoToUrl("https://localhost:xxxxx/"); if (webDriver.PageSource.Contains("Super

我想用selenium和NUnit测试网页上是否有特定的文本。 如果文本存在,则测试应通过。 如果文本不在当前页面上,则应单击“下一页”按钮,然后再次搜索新页面

现在我得到了这个:

IWebDriver webDriver = new ChromeDriver();

webDriver.Navigate().GoToUrl("https://localhost:xxxxx/");

if (webDriver.PageSource.Contains("Super Handy"))
        {
            Assert.Pass();
        } else
        {
            webDriver.FindElement(By.XPath("//svg[@class=" +
                "'mud-icon-root mud-svg-icon mud-inherit-text mud-icon-size-medium']"));

        }
我尝试了“continue”,因为它应该从一开始就启动if条件。 在过去的一个小时里试图找到一个解决方案,但现在结束了,我在这里问了我的问题


谢谢

您的XPath不会以这种方式工作。
试试这个:

webDriver.FindElement(By.XPath("//*[name()='svg' and @class='mud-icon-root mud-svg-icon mud-inherit-text mud-icon-size-medium']"));
看看这是否有效

while(webDriver.PageSource!=null){
    if(webDriver.PageSource.contains("your text")){
          Assert.Pass();
       }else{
        webDriver.FindElement(By.XPath("//*[name()='svg' and @class='mud-icon-root mud-svg-icon mud-inherit-text mud-icon-size-medium']")).Click();
        //Can add wait time for the page to load completely here
        Console.WriteLine(webDriver.Title);
        continue;
       }
}

嗯,事实上,我在过去的几行中不停地使用这种方法,而且效果很好。这里的问题更多,当条件不为真时,我如何使if条件从头开始:)你到底想从那里开始做什么?我正在向列表中添加数据。该列表有不同的页面,其中充满了新的数据。我想检查我添加到列表中的数据是否存在于列表中。使用这个方法,我还想测试下一页的按钮是否有效。它只需反复启动if条件,直到找到数据并调用“Assert.Pass()”;