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)); } }

unknown error: Chrome failed to start: exited abnormally (Driver info: chromedriver=2.9

I finally managed to get Selenium tests starting the Chrome Driver on my laptop (server). The important bit is to use Xvfb. Don’t ask me why but once you accept this fact follow these steps (more detailed than @Anon answer) In you Jenkins settings add a global property key : DISPLAY value:0:0 On your server … Read more

How to run a method before all tests in all classes?

Using session fixture as suggested by hpk42 is great solution for many cases, but fixture will run only after all tests are collected. Here are two more solutions: conftest hooks Write a pytest_configure or pytest_sessionstart hook in your conftest.py file: # content of conftest.py def pytest_configure(config): “”” Allows plugins and conftest files to perform initial … Read more

How do I pass options to the Selenium Chrome driver using Python?

Found the chrome Options class in the Selenium source code. Usage to create a Chrome driver instance: from selenium import webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options() chrome_options.add_argument(“–disable-extensions”) driver = webdriver.Chrome(chrome_options=chrome_options)

How to capture the screenshot of a specific element rather than entire page using Selenium Webdriver?

We can get the element screenshot by cropping entire page screenshot as below: driver.get(“http://www.google.com”); WebElement ele = driver.findElement(By.id(“hplogo”)); // Get entire page screenshot File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); BufferedImage fullImg = ImageIO.read(screenshot); // Get the location of element on the page Point point = ele.getLocation(); // Get width and height of the element int eleWidth = … Read more

XPath: difference between dot and text()

There is a difference between . and text(), but this difference might not surface because of your input document. If your input document looked like (the simplest document one can imagine given your XPath expressions) Example 1 <html> <a>Ask Question</a> </html> Then //a[text()=”Ask Question”] and //a[.=”Ask Question”] indeed return exactly the same result. But consider … Read more