Selenium Code Snippets
Selenium Code Snippets
� Running JavaScript via the driver
Although if we create a function out of it, it does not run.
JavascriptExecutor jsRunner = (JavascriptExecutor) driver;
// This will get us the name of the browser on which the test is running
String jsString = "return navigator.appCodeName";
System.out.println ("BrowserName = " + jsRunner.executeScript(jsString));
� Code to get the text of all the links on a web page
List<WebElement> allLinks = driver.findElements(By.tagName("a"));
for (WebElement link : allLinks){
System.out.println("Link text = " + link.getText());
}