Found 466 Questions for Selenium

Difference b/w getText() and getAttribute() in Selenium WebDriver

Kiran Kumar Panigrahi
Updated on 28-Jul-2022 08:13:54
Selenium WebDriver is an automation tool that is used to automate the testing of web applications and make sure they work as expected. Automation means the programmer doesn't have to write testing scripts; Selenium can write test cases without any script.Selenium supports a wide variety of programming languages such as Java, Python, PHP, Ruby, C#, Perl, Scala, etc. which means Selenium can provide test cases in any of these languages. It supports all the popular browsers such as Chrome, Firefox, Safari, and Internet Explorer. Selenium is an open-source tool which makes it even more popular among developers.In this article, we ... Read More

Using Selenium in Python to click/select a radio button.

Debomita Bhattacharjee
Updated on 28-Aug-2020 13:00:04
We can select/click the radio button with Selenium. In an html document, each radio button has an attribute type set to a value as radio. In order to select a radio button, we shall first identify it and then apply the click() method to it.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/selenium/selenium_automation_practice.htm") # identify element and click() l=driver.find_element_by_xpath("//input[@value='2']") l.click() driver.close()Output

How to open a new window on a browser using Selenium WebDriver for python?

Debomita Bhattacharjee
Updated on 28-Aug-2020 12:58:47
We can open a new window on a browser with Selenium webdriver. There are multiple ways to achieve this. Selenium can execute commands in Javascript with the help of the execute_script() method which is one of the ways of opening a new window. Then we shall use switch_to.window() method to shift focus to a particular window at a time.Syntax −driver.execute_script("window.open('');")ExampleCode Implementation with execute_script() method.from selenium import webdriver urlA = "https://www.tutorialspoint.com/about/about_careers.htm" urlB = "https://www.tutorialspoint.com/questions/index.php" driver = webdriver.Chrome (executable_path="C:\chromedriver.exe") # maximize with maximize_window() driver.maximize_window() driver.get(urlA) print("Page Title of urlA : " + driver.title) # open new window with execute_script() driver.execute_script("window.open('');") # switch ... Read More

How can I get all element's immediate children with css selectors using selenium?

Debomita Bhattacharjee
Updated on 28-Aug-2020 12:57:06
We can get all element’s immediate children with css selectors. We have to use findElements() method to get immediate children. This method will return a list of elements matching css selector.In a css selector if we need to traverse from parent to child we use > symbol. To get all the immediate children we have to specify * symbol after parent node in the css expression. So the customized css should be parent > *.So for a , the css for immediate children shall be ul.toc.chapters >*.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; import java.util.List; public ... Read More

How to get content of entire page using Selenium?

Debomita Bhattacharjee
Updated on 28-Aug-2020 12:55:05
We can get the content of the entire page using Selenium. There are more than one ways of achieving it. To get the text of the visible on the page we can use the method findElement(By.tagname()) method to get hold of . Next can then use the getText() method to extract text from the body tag.Syntax −WebElement l=driver.findElement(By.tagName("body")); String t = l.getText();The next approach to get the content of the entire page is to use the getPageSource() method.Syntax −String l = driver.getPageSource();ExampleCode Implementation with tag.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 TextContent{    public ... Read More

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

Debomita Bhattacharjee
Updated on 28-Aug-2020 12:52:17
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
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
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
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
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
Advertisements