Found 719 Articles for Testing Tools

Python + Selenium | How to locate elements in span class & not unique ID

Debomita Bhattacharjee
Updated on 08-Apr-2021 07:28:32

4K+ Views

We can locate elements in span class and not unique id with the help of the Selenium webdriver. We can identify an element having a class attribute with the help of the locator xpath, css or class name.To locate elements with these locators we have to use the By.xpath, By.xpath or By.cssSelector method. Then pass the locator value as a parameter to this method.Let us see the html code of a button having a span class and try to identify it.Examplefrom selenium import webdriver #set chromodriver.exe path driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) #launch URL driver.get("https://www.tutorialspoint.com/index.htm") l = driver.find_element_by_id("textemail") l.send_keys("abc@gmail.com") #get value ... Read More

How to handle "Plugin blocked" pop up using Selenium Python?

Debomita Bhattacharjee
Updated on 08-Apr-2021 07:27:59

2K+ Views

We can handle plugin popup using Selenium webdriver in Python. Whenever a popup comes on page, we cannot inspect elements within the popup and identify them.Also, in order to access other elements on the page, we have to first either accept default has access to the main page. To interact with the popup, we have to explicitly shift the driver focus with the help of the switch_to.alert() method.The popup mainly consists of a message along with Ok and Cancel buttonsto accept and dismiss a popup respectively. To accept a popup, the method switch_to.alert().accept() is used.To dismiss a popup, the method ... Read More

Find div element by multiple class names in Selenium?

Debomita Bhattacharjee
Updated on 07-Apr-2021 09:28:49

8K+ Views

We can find elements by multiple class names. If there is an element having more than one value separated by spaces set for the class attributes, it is called the compound class names.Let us see the HTML code of such web elements having compound class names −We shall get an exception if we use both the values - toc and chapters with the class name locator for the above scenario. Instead, the rule is to have only one class attribute value with the class name locator.SyntaxWebElement l = driver.findElement(By.className("toc")); //Invalid locator value with className locator WebElement l = driver.findElement(By.className("toc chapters"));Exampleimport ... Read More

How test runner prioritize test classes for execution in Selenium?

Debomita Bhattacharjee
Updated on 07-Apr-2021 09:26:24

593 Views

We can prioritize tests in TestNG during execution. It must be noted that priority can only be set for test methods with @Test annotation. Lower the priority number set for a test method, higher the priority it gets during execution.Only integer value (positive, zero or negative) can be set as priority. A decimal number can also be set as priority, however it is required to be converted to integer value via typecasting.A test method cannot have multiple priority numbers. Also, the priority for a test method cannot be set from the TestNG XML file.Syntaxpublic class TestNG {    @Test (priority ... Read More

TestNG error:- Cannot find class in classpath using Selenium

Debomita Bhattacharjee
Updated on 07-Apr-2021 09:24:27

10K+ Views

We may encounter Cannot find class in classpath exception while executing tests in Selenium with TestNG framework. This can be caused because of the following reasons −In the TestNG XML, the class tag having the name attribute should not have the .java extension.In the TestNG XML, the class file is incorrect and hence unable to determine the classpath of the class.Errors within the project are present, and may require a clean project.In the TestNG XML, the class file name is incorrectThe below image shows an example of this error −Exampleimport org.testng.annotations.Test; public class TestNGP {    @Test    public void ... Read More

How to run multiple test cases using TestNG Test Suite in Selenium?

Debomita Bhattacharjee
Updated on 07-Apr-2021 09:23:19

4K+ Views

We can run multiple test cases using TestNG test suite in Selenium webdriver. To execute test cases simultaneously, we have to enable parallel execution in TestNG.A TestNG execution is driven by the TestNG xml file. To trigger parallel execution we have to use the attributes – parallel and thread-count. The attribute threadcount controls the number of threads to be triggered while executing the tests in a parallel mode. The values that can be set for parallel attributes are – tests, classes, instances and methods.Exampleimport org.testng.annotations.Test; public class TestNG15 {    @Test    public void tC1() {       System.out.println("Test ... Read More

What is Cucumber dry run in Selenium?

Debomita Bhattacharjee
Updated on 07-Apr-2021 09:22:01

8K+ Views

Cucumber dry run is used for compilation of the Step Definition and Feature files and to verify the compilation errors. The value of dry run can be either true or false. The default value of dry run is false and it is a part of the Test Runner Class file.In case the value of dry run is set to true, Cucumber will verify individual steps in the Feature file and the implementation code of steps in Feature file within the Step Definition file.A message is thrown, if any of the steps in the Feature file is not implemented in the ... Read More

How do I resolve the ElementNotInteractableException in Selenium WebDriver?

Debomita Bhattacharjee
Updated on 07-Apr-2021 09:18:35

3K+ Views

We get the ElementNotInteractableException in Selenium if an element is available in DOM but not in a condition to be interacted. Some of the reasons for this exception are −There may be a covering of another element on the element with which we want to interact with. This overspread of an element over the other can be temporary or permanent. To resolve a temporary overspread, we can wait for an expected condition for the element.We can wait for the expected condition of invisibilityOfElementLocated for the overlay element. Or, wait for the expected condition of elementToBeClickable for the element with which ... Read More

Unable to locate an element using xpath error in selenium-java

Debomita Bhattacharjee
Updated on 07-Apr-2021 09:18:08

8K+ Views

We may encounter the error - unable to locate element while working with Selenium webdriver. This leads to NoSuchElementException. This type of exception is thrown when there is no element on the page which matches with the locator value.If error is encountered, we can fix it by the following ways −Check if there is any syntax error in our xpath expression.Add additional expected wait conditions for the element.Use an alternative xpath expression.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class XpathError{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", ... Read More

Equivalent of waitForVisible/waitForElementPresent in Selenium WebDriver tests using Java?

Debomita Bhattacharjee
Updated on 07-Apr-2021 09:14:36

539 Views

There are equivalent methods for waitForVisible/waitForElementPresent in Selenium webdriver. They are a part of the synchronization concept in Selenium.The implicit and explicit waits are the two types of waits in synchronization.The implicit wait is the wait applied to the webdriver for a specified amount of time for all elements. Once this time has elapsed and an element is still not available, an expectation is thrown.Syntaxdriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);ExampleCode Implementation with implicit waitimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class ImplctWait{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", ... Read More

Advertisements