Found 719 Articles for Testing Tools

Find Element and FindElements in Selenium

Debomita Bhattacharjee
Updated on 06-Apr-2021 08:02:47

1K+ Views

The methods findElement and findElements are used to identify elements on the webpage. Both these methods can be used with locators like id, css, class, name, xpath, css, link text, tagname and partial link text.The method findElement is used to identify an element which matches with the locator (used with By object) passed as a parameter to that method. If there is no matching element, then NoSuchElementException is thrown.The method findElements is used to identify a list of elements which matches with the locator (used with By object) passed as a parameter to that method. If there is no matching ... Read More

Find elements using Selenium WebDriver?

Debomita Bhattacharjee
Updated on 06-Apr-2021 08:01:10

383 Views

We can find elements using Selenium webdriver with the help of the findElements method. This can be applied to the locators like id, class, name, link text, partial link text, css, xpath and tagname.The findElements method returns a list of elements which match with the locator (with the By object) passed as a parameter to the method. To count the number of elements returned by the list, the method size is used. If there are no matching elements, an empty list is returned.The below image shows the list of methods available with findElements.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; ... Read More

Java Selenium Chromedriver.exe Does not Exist IllegalStateException

Debomita Bhattacharjee
Updated on 06-Apr-2021 08:01:42

4K+ Views

An IllegalStateException is thrown while working with Chrome browser if the chromedriver.exe file path is set incorrectly in the method System.setProperty. Once this executable file is downloaded, it has to be extracted. Then its path should be copied and added as a parameter to the System.setProperty method.SyntaxSystem.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\DebomitaJava\chromedriver.exe")Also, it must be remembered that, for Windows, we have to specify the .exe extension while including the path. But it is not required for Mac or Ubuntu. We should also ensure that the chromedriver.exe file that we are using is compatible with the local Chrome browser version.Let us see an example for ... Read More

How to find an element using the attribute “HTML tag name” in Selenium?

Debomita Bhattacharjee
Updated on 06-Apr-2021 08:02:02

1K+ Views

We can find an element using the element tag name with Selenium webdriver with the help of locator tagname. To locate an element with tagname, we have to use the By.tagName method.In the html code, a tagname is usually enclosed by , for example, an anchor tag represents links on the page. An input tag represents text boxes, checkboxes or radio buttons. Let us look at the html code of an element and try to identify it with its tagname −In the above image, the text – You are browsing the best resources for has the h4 tag.SyntaxWebElement e ... Read More

How to find an element using the attribute “class name” in Selenium?

Debomita Bhattacharjee
Updated on 08-Nov-2023 00:26:04

23K+ Views

We can find an element using the attribute class name with Selenium webdriver using the locators - class name, css, or xpath. To identify the element with css, the expression should be tagname[class='value'] and the method to be used is By.cssSelector. To identify the element with xpath, the expression should be //tagname[@class='value']. Then, we have to use the method By.xpath to locate it. To locate an element with a locator class name, we have to use the By.className method. Let us look at the html code of an element with class attribute − Syntax WebElement e = driver. findElement(By.className("input")); ... Read More

Check that the element is clickable or not in Selenium WebDriver

Debomita Bhattacharjee
Updated on 06-Apr-2021 07:52:00

18K+ Views

We can check if the element is clickable or not in Selenium webdriver using synchronization. In synchronization, there is an explicit wait where the driver waits till an expected condition for an element is met.To verify, if the element can be clicked, we shall use the elementToBeClickable condition. A timeout exception is thrown if the criteria for the element is not satisfied till the driver wait time.SyntaxWebDriverWait wt = new WebDriverWait(driver, 5); wt.until(ExpectedConditions.elementToBeClickable (By.className("s-buy")));We have to add - import org.openqa.selenium.support.ui.ExpectedConditions and import org.openqa.selenium.support.ui.WebDriverWait statements to implement ExpectedConditions in our code.Exampleimport 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; import ... Read More

What is the difference between relative and absolute XPath in Selenium?

Debomita Bhattacharjee
Updated on 08-Nov-2023 00:02:51

25K+ Views

We can have two ways of creating an xpath – relative and absolute. The absolute xpath has the complete path beginning from the root to the element which we want to identify.An absolute xpath starts with the / symbol. One drawback with the absolute xpath is that if there is any change in attributes beginning from the root to the element, our absolute xpath will become invalid.The relative xpath starts by referring to the element that we want to identify and not from the root node. A relative xpath starts with the // symbol. It is mainly used for automation ... Read More

How to verify color of a web element in Selenium Webdriver?

Debomita Bhattacharjee
Updated on 03-Apr-2021 11:03:34

21K+ Views

We can verify the color of a webelement in Selenium webdriver using the getCssValue method and then pass color as a parameter to it. This returnsthe color in rgba() format.Next, we have to use the class Color to convert the rgba() format to Hex. Let us obtain the color an element highlighted in the below image. The corresponding color for the element is available under the Styles tab in Chrome browser.The color of the element is also provided in the hex code #797979.SyntaxWebElement t = driver.findElement(By.tagName("h1")); String s = t.getCssValue("color"); String c = Color.fromString(s).asHex();Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import ... Read More

How to open browser window in incognito/private mode using python selenium webdriver?

Debomita Bhattacharjee
Updated on 03-Apr-2021 11:00:57

7K+ Views

We can open a browser window in incognito/private mode with Selenium webdriver in Python using the ChromeOptions class. We have to create an object of the ChromeOptions class.Then apply the method add_argument to that object and pass the parameter -- incognito has a parameter. Finally, this information has to be passed to the webdriver object.Syntaxc = webdriver.ChromeOptions() c.add_argument("--incognito")Examplefrom selenium import webdriver #object of ChromeOptions class c = webdriver.ChromeOptions() #incognito parameter passed c.add_argument("--incognito") #set chromodriver.exe path driver = webdriver.Chrome(executable_path="C:\chromedriver.exe", options=c) driver.implicitly_wait(0.5) #launch URL driver.get("https://www.tutorialspoint.com/tutor_connect/index.php")OutputRead More

How to capture the text from Alert Message in Selenium Webdriver?

Debomita Bhattacharjee
Updated on 03-Apr-2021 11:00:34

3K+ Views

We can capture the text from the alert message in Selenium webdriverwith the help of the Alert interface. By default, the webdriver object has control over the main page, once an alert pop-up gets generated, we have to shift the webdriver focus from the main page to the alert.This is done with the help of the switchTo().alert() method. Once the driver focus is shifted, we can obtain the text of the pop-up with the help of the method switchTo().alert().getText(). Finally we shall use the accept method to accept the alert and dismiss method to dismiss it.Let us take an example ... Read More

Advertisements