What is the difference between a CSS and XPath selector? And which is better with respect to performance for cross-browser testing?

CSS selectors perform far better than XPath selectors, and it is well documented in Selenium community. Here are some reasons: XPath engines are different in each browser, hence making them inconsistent Internet Explorer does not have a native XPath engine, and therefore Selenium injects its own XPath engine for compatibility of its API. Hence we … Read more

How can I get text of an element in Selenium WebDriver, without including child element text?

Here’s a general solution: def get_text_excluding_children(driver, element): return driver.execute_script(“”” return jQuery(arguments[0]).contents().filter(function() { return this.nodeType == Node.TEXT_NODE; }).text(); “””, element) The element passed to the function can be something obtained from the find_element…() methods (i.e., it can be a WebElement object). Or if you don’t have jQuery or don’t want to use it, you can replace … Read more

“selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element” while clicking a ‘Next’ button with Selenium

This error message… selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {“method”:”name”,”selector”:”submitNext”} (Session info: chrome=66.0.3359.170) (Driver info: chromedriver=2.36.540470) …implies that the ChromeDriver was unable to locate the desired element. Locating the desired element As per the HTML you have shared to click on the element you can use either of the following Locator Strategies: … Read more

What is the best way to avoid NoSuchElementException in Selenium?

You can never be sure that element will be found, actually this is purpose of functional tests – to tell you if anything changed on your page. But one thing which definitely helps is to add waits for the elements which are often causing NoSuchElementException like WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id<locator>));

How to skip the rest of tests in the class if one has failed?

I like the general “test-step” idea. I’d term it as “incremental” testing and it makes most sense in functional testing scenarios IMHO. Here is a an implementation that doesn’t depend on internal details of pytest (except for the official hook extensions). Copy this into your conftest.py: import pytest def pytest_runtest_makereport(item, call): if “incremental” in item.keywords: … Read more