Capturing JavaScript error in Selenium

I’m doing this to capture JavaScript errors: [TestCleanup] public void TestCleanup() { var errorStrings = new List<string> { “SyntaxError”, “EvalError”, “ReferenceError”, “RangeError”, “TypeError”, “URIError” }; var jsErrors = Driver.Manage().Logs.GetLog(LogType.Browser).Where(x => errorStrings.Any(e => x.Message.Contains(e))); if (jsErrors.Any()) { Assert.Fail(“JavaScript error(s):” + Environment.NewLine + jsErrors.Aggregate(“”, (s, entry) => s + entry.Message + Environment.NewLine)); } }

How to open Chrome browser console through Selenium?

To open chrome browser console you can use the ChromeOptions class with –auto-open-devtools-for-tabs argument as follows: Test Configuration: Selenium: Selenium Standalone Server v3.14.0 ChromeDriver: ChromeDriver 2.46.628402 Chrome: Google Chrome 72.0.3626.96 Code Block: import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; public class A_Chrome_Browser_Console { public static void main(String[] args) { System.setProperty(“webdriver.chrome.driver”, “C:\\Utility\\BrowserDrivers\\chromedriver.exe”); ChromeOptions options = new ChromeOptions(); … Read more

Only local connections are allowed Chrome and Selenium webdriver

This is just an informational message. Your issue might be a missmatch between the versions of chromedriver and selenium-server-standalone. Try with the latest selenium version 3.0, it is working for me. Please not that for selenium 3.0 you need to specify the driver first and after the selenium server. With the new selenium, which is … Read more

How to get attribute value inside a div in webdriver

ieDriver.findElement(By.xpath(“//div[@class=”assign_grid assign_grid_selected”]”)).getAttribute(“login”); I’d also check to ensure that the locators you are using are only bringing back that one element, and not more – to check this, run the same thing using .findElements and verify only one single result is returned. It is common that there are hidden elements in the HTML, and your locator … Read more

Switch between two browser windows using Selenium WebDriver

you can use following code to switch between windows based on the window title private void handleMultipleWindows(String windowTitle) { Set<String> windows = driver.getWindowHandles(); for (String window : windows) { driver.switchTo().window(window); if (driver.getTitle().contains(windowTitle)) { return; } } } Similary you could use URL or some other criteria to switch windows.

How to switch control from child window to parent window in selenium webdriver?

Use this code: // Get Parent window handle String winHandleBefore = _driver.getWindowHandle(); for (String winHandle : _driver.getWindowHandles()) { // Switch to child window driver.switchTo().window(winHandle); } // Do some operation on child window and get child window handle. String winHandleAfter = driver.getWindowHandle(); //switch to child window of 1st child window. for(String winChildHandle : _driver.getWindowHandles()) { // … Read more

What are the benefits of using Marionette FirefoxDriver instead of the old Selenium FirefoxDriver for a Selenium tester?

The main advantage for using the Mozilla-provided, Marionette-based Geckodriver solution is that it works for versions of Firefox 48 and higher. The legacy driver provided and maintained by the Selenium project doesn’t work for Firefox 48 or higher, and will never work for those versions of Firefox. The legacy driver is implemented as a Firefox … Read more

isElementPresent is very slow in case if element does not exist.

Here you are missing somethings that is why it is waiting If there is not element. findElement will wait for an element implicitly specified time. so need to set that time to zero in that method. isElementPresent(WebDriver driver, By by) { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); try { driver.findElement(by); return true; } catch (NoSuchElementException e) { return false; … Read more