Found 871 Articles for Automation Testing

Get the text from multiple elements with the same class in Selenium for Python?

Debomita Bhattacharjee
Updated on 28-Aug-2020 12:52:17

6K+ Views

We can get text from multiple elements with the same class in Selenium webdriver. We have to use find_elements_by_xpath(), find_elements_by_class_name() or find_elements_by_css_selector() method which returns a list of all matching elements.Syntax −l=driver.find_elements_by_class_name("gsc-input")Next we shall get the size of the list with len method. We shall iterate through this list and obtain the text with text method.ExampleCode Implementation.from selenium import webdriver driver = webdriver.Chrome (executable_path="C:\chromedriver.exe") # maximize with maximize_window() driver.maximize_window() driver.get("https://www.justdial.com/Bangalore/Bakeries") # identify elements of same classname l=driver.find_elements_by_class_name("store-name") # iterate through list and get text for i in l:    print("Store names:"+ i.text) driver.close()OutputRead More

How to type in textbox using Selenium WebDriver with Java?

Debomita Bhattacharjee
Updated on 28-Aug-2020 12:50:42

6K+ Views

We can type in a textbox using Selenium webdriver. We shall use the sendKeys() method to type in the edit box. It is an in-built method in Selenium. Let us consider a text box where we shall enter some text.First of all, we would identify the field with one of the locators and apply sendKeys() method on it.Syntax −driver.findElement(By.id("text-bx")).sendKeys("Tutorialspoint")ExampleCode Implementation.import 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 InputTxt{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver",       "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url ... Read More

How do I get the src of an image in Selenium?

Debomita Bhattacharjee
Updated on 28-Aug-2020 12:47:08

11K+ Views

We can get the source of an image in Selenium. An image in an html document has tagname. Each image also has an attribute src which contains the source of image in the page.To fetch any attribute in Selenium, we have to use the getAttribute() method. The method takes the attribute name as a parameter. So to get the src attribute, we have to write getAttribute("src").ExampleCode Implementation.import 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 Imagesrc{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver(); ... Read More

How to handle frame in Selenium WebDriver using java?

Debomita Bhattacharjee
Updated on 28-Aug-2020 12:43:32

1K+ Views

We can handle frames in Selenium webdriver. A frame is identified with tag in the html document. A frame is used to insert an HTML document inside another HTML document.To work with frames, we should first understand switching between frames and identify the frame to which we want to move. There are multiple ways to switch to frames −switchTo().frame(n) - The index of frame is passed as an argument to switch to. The frame index starts from 0.Syntax −driver.switchTo().frame(1), we shall switch to the frame with index 1.switchTo().frame(name) - The frame id or name is passed as an argument ... Read More

How can I check if some text exist or not in the page using Selenium?

Debomita Bhattacharjee
Updated on 28-Aug-2020 12:41:05

17K+ Views

We can check if some text exists or not in a page with Selenium. There are more than one ways to find it. We can use the getPageSource() method to fetch the full page source and then verify if the text exists there. This method returns content in the form of string.We can also check if some text exists with the help of findElements method with xpath locator. Then we shall use the text() function to create a customized xpath. The findElements() method returns a list of elements. We shall use the size() method to verify if list size is ... Read More

How to get text with selenium web driver in python?

Debomita Bhattacharjee
Updated on 28-Aug-2020 12:37:27

6K+ Views

We can extract text of an element with a selenium webdriver. This is done with the help of a text method. It fetches the text in an element which can be later validated.First we need to identify the element with the help of any locators. Suppose we want to get the text of an element in below page.ExampleCode Implementation.from selenium import webdriver driver = webdriver.Chrome (executable_path="C:\chromedriver.exe") # maximize with maximize_window() driver.maximize_window() driver.get("https://www.tutorialspoint.com/index.htm") # identify element l=driver.find_element_by_css_selector("h4") # get text and print print("Text is: " + l.text) driver.close()OutputRead More

Getting the URL of the current page using Selenium WebDriver.

Debomita Bhattacharjee
Updated on 28-Aug-2020 12:35:45

17K+ Views

We can obtain the URL of the current page with Selenium webdriver. This is achieved with the help of getCurrentUrl() method. It fetches the URL of the opened application. This method accepts no parameters and strings the URL in the form of String.Syntax −String strUrl = driver.getCurrentUrl();ExampleCode Implementation.import 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 CurrentUrl{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url = "https://www.tutorialspoint.com/index.htm";       driver.get(url);       driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);       // ... Read More

How does selenium webdriver upload files to the browser?

Debomita Bhattacharjee
Updated on 28-Aug-2020 12:33:52

929 Views

We can upload files to the browser with the help of Selenium webdriver. This is done with the help of sendKeys() method on the element which does the selection of the file by specifying the path of the file to be uploaded.While working on file upload functionality, we need to click on the Browse button. This is taken care of by webdriver for elements with attribute type having value as file. Also, the path of the file to be uploaded should be correct.ExampleCode Implementation.import 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 FileUpld{    public static void ... Read More

How to Maximize window in chrome using webDriver (Python)?

Debomita Bhattacharjee
Updated on 28-Aug-2020 12:30:48

2K+ Views

We can maximize windows on Chrome with a webdriver. While working on any automated test cases, if the browser opens in maximized mode then the probability of the scripts getting failed lessens.This is because if the element is visible, then the chances of its interaction increases. Also, if the window is maximized, then the testers or developers working on them gets a better visibility of the test steps.Some of the applications open in maximized mode automatically. Applying maximizing techniques on them does not have any impact on them. Let us see the methods with which we can maximize window in ... Read More

How to select checkboxes using selenium java webdriver?

Debomita Bhattacharjee
Updated on 28-Aug-2020 12:29:06

2K+ Views

We can select the checkbox with Selenium. In an html document, each checkbox has an attribute type set to a value as checkbox. In order to select a checkbox, we shall first identify a checkbox with any locator and then apply the click() method to it.ExampleCode Implementation.import 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 CheckBoxSelect{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url ="https://www.tutorialspoint.com/selenium/selenium_automation_practice.htm";       driver.get(url);       driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);       // identify element ... Read More

Advertisements