-1

I need to open all links from a page at a specific URL. If the link opens I need to check the page content and verify it does not contain specific text.

I used Selenide which is built on selenium, and tried the following:

String[] links = null;
int linksCount = 0;
 System.setProperty("webdriver.chrome.driver", "Resources/chromedriver1.exe");
     WebDriverRunner.setWebDriver(new ChromeDriver());   
     driver= WebDriverRunner.getWebDriver();
    open("myURL");
    List<WebElement> linksize =      WebDriverRunner.getWebDriver().findElements(By.tagName("a")); 
    linksCount = linksize.size();
    out.println("Total no of links Available: "+linksCount);
    links= new String[linksCount];
    out.println("List of links Available: ");  
    // print all the links from webpage 
    for(int i=0;i<linksCount;i++)
    {
    links[i] = linksize.get(i).getAttribute("href");
    System.out.println(linksize.get(i).getAttribute("href"));
    } 
    // navigate to each Link on the webpage
    for(int i=0;i<linksCount;i++)
    {
        if(links[i] != null)
            {
                if(!links[i].contains("javascript"))
                {
                    System.out.println(links[i]);
                    driver.navigate().to(links[i]);
                    Selenide.sleep(7);
                    WebElement error = $(Selectors.byText("no information!")); 
                    $(error).shouldNotBe(visible)
                    .shouldNotBe(text("information!"));
                }
            }

    }

I used the same solution in this link. but I have this exception while checking:

unknown error: unhandled inspector error: {"code":-32603,"message":"Cannot navigate to invalid URL"} (Session info: chrome=49.0.2623.87)

org.openqa.selenium.WebDriverException: unknown error: unhandled inspector error: {"code":-32603,"message":"Cannot navigate to invalid URL"} (Session info: chrome=49.0.2623.87) (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 4 milliseconds Build info: version: '2.50.1', revision: 'd7fc91b', time: '2016-01-29 19:04:49'

I used this chrome driver version from here

What could be generating this error?

Community
  • 1
  • 1
Hana90
  • 943
  • 5
  • 17
  • 37

2 Answers2

1

From the error log you posted, its clear that "Cannot navigate to invalid URL". Provide a valid url and check - Thanks

karusai
  • 126
  • 1
  • 1
  • 9
  • I am exclude any url == null or emptyor contaiing (javascript) so what are the invalid urls? – Hana90 Mar 20 '16 at 19:28
1

Almost certainly this is failing long before you loop through your links.

The following line will try to load what is clearly not a valid URL, which completely explains the error you got.

open("myURL");

Presumably you meant to pass in a variable named myURL?

Andrew Regan
  • 5,087
  • 6
  • 37
  • 73
  • Your code is wrong, `"myURL"` is not a valid URL. As I said, you probably meant to pass the value of a variable, which may evaluate to "vanilla.sa", though you didn't tell us that. – Andrew Regan Mar 20 '16 at 19:29