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?