Found 719 Articles for Testing Tools

How to input text in the text box without calling the sendKeys() using Selenium?

Debomita Bhattacharjee
Updated on 03-Apr-2021 10:57:57

16K+ Views

We can input text in the text box without the method sendKeys with thehelp of the JavaScript Executor. Selenium executes JavaScript commands with the help of the executeScript method.The JavaScript command to be run is passed as parameter to the method. To enter text we shall first identify the input box with the JavaScript method document.getElementById. Then we have to apply the value method on it.Let us enter text Selenium in the below input box −SyntaxJavascriptExecutor j = (JavascriptExecutor)driver; j.executeScript ("document.getElementById('gsc-i-id1').value='Selenium'");Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.JavascriptExecutor; public class JsEnterText{    public static void main(String[] ... Read More

How to get all options of a dropdown using Python Selenium webdriver?

Debomita Bhattacharjee
Updated on 03-Apr-2021 10:57:32

6K+ Views

We can obtain all options of a dropdown with Selenium webdriver inPython using the method options. It returns a list of the options in the dropdown.Then we have to use the method text, to get the option text.A dropdown is represented by select tag and its available options are represented by the tagname option. To handle dropdown in Selenium, we have to take the help of the Select class.Let us see the html code of a dropdown along with its options – By Subject and By Name.Syntaxl = driver.find_element_by_name("selType") d = Select(l)for opt in d.options -m = opt.textExamplefrom selenium import ... Read More

How to click on image in selenium webdriver Python?

Debomita Bhattacharjee
Updated on 03-Apr-2021 10:52:22

3K+ Views

We can click on an image with Selenium webdriver in Python using the method click. First of all, we have to identify the image with the help of any of the locators like id, class, name, css, xpath, and so on. An image in the html code is represented by the img tagname.Let us see the html code of an image element.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; public class ImageClk{    public static void main(String[] args) {       System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe");       WebDriver driver = new FirefoxDriver();       //implicit wait   ... Read More

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

Debomita Bhattacharjee
Updated on 03-Apr-2021 10:50:15

12K+ Views

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

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

Debomita Bhattacharjee
Updated on 03-Apr-2021 10:49:54

18K+ Views

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

How to get Tooltip Text in Selenium Webdriver?

Debomita Bhattacharjee
Updated on 03-Apr-2021 10:49:31

5K+ Views

We can get the tooltip text in Selenium webdriver with help of the method - getAttribute. The attribute title should be passed as a parameter to this method.This technique is only applicable if the element has a title attribute.The tooltip text is the one which gets displayed on hovering the mouse over the element. In the below html code, an element having a tooltip has the attribute title and the value set for title is actually the tooltip text.The below image shows the menu Coding Ground showing the tooltip text as - Coding Ground - Free Online IDE and Terminal.SyntaxWebElement ... Read More

Verifying whether an element present or visible in Selenium Webdriver

Debomita Bhattacharjee
Updated on 12-Sep-2023 01:07:53

35K+ Views

We can verify whether an element is present or visible in a page with Selenium webdriver. To check the presence of an element, we can use the method – findElements.The method findElements returns a list of matching elements. Then, we have to use the method size to get the number of items in the list. If the size is 0, it means that this element is absent from the page.Syntaxint j = driver.findElements(By.id("txt")).size();To check the visibility of an element in a page, the method isDisplayed() is used. It returns a Boolean value( true is returned if the element is visible, ... Read More

How to find Elements in a Webpage using JavaScript in Selenium?

Debomita Bhattacharjee
Updated on 03-Apr-2021 10:35:18

2K+ Views

We can find elements in a web page with the help of JavaScript. We can also validate the elements returned by the JavaScript methods in the browser Console (Pressing F12). JavaScript methods to find elements are −getElementsByTagnameTo obtain a collection of elements with the matching tagname passed as parameter to the method. If there are no matching elements, an empty collection is returned.Syntaxdocument.getElementsByTagName("") To get the first matching element, document.getElementsByTagName("")[0]getElementsByNameTo obtain a collection of elements with the matching value of name attribute passed as parameter to the method. If there are no matching elements, an empty collection is returned.Syntaxdocument.getElementsByName("") To ... Read More

How to click on a hyper link using linkText in Selenium?

Debomita Bhattacharjee
Updated on 03-Apr-2021 10:34:42

9K+ Views

A hyperlink on a page is identified with the anchor tag. To click a link, we can use the link text locator which matches the text enclosed within the anchor tag.We can also use the partial link text locator which matches the text enclosed within the anchor tag partially. NoSuchElementException is thrown if there is no matching element found by both these locators.SyntaxWebElement t =driver.findElement(By.partialLinkText("Refund")); WebElement m =driver.findElement(By.linkText("Refund Policy"));Let us make an attempt to click a link Refund Policy on the below page −ExampleCode Implementation with linkTextimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; public class LnkClick{   ... Read More

How to get typed text from a textbox by using Selenium Webdriver?

Debomita Bhattacharjee
Updated on 03-Apr-2021 10:34:18

2K+ Views

We can get the typed text from a textbox with Selenium webdriver. Firstly, we have to enter text in the text box (after being identified with any locators) with the help of the sendKeys method.Then apply the method getAttribute to obtain the text entered in that field and pass the parameter value to that method. Let us make an attempt to obtain the value entered in the Google search box −SyntaxWebElement m = driver.findElement(By.name("q")); String st = m.getAttribute("value");Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; public class GetTextTyped{    public static void main(String[] args) {       ... Read More

Advertisements