
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 517 Articles for Selenium

11K+ Views
We can find an element in a sub-element with Selenium webdriver. First of all we need to identify the element with help of any of the locators like id, class, name, xpath or css. Then we have to identify the sub-element with the findElements(By.xpath()) method.We can identify the sub-element from the element, by localizing it with the element and then passing the expression (./child::*) as a parameter to the findElements(By.xpath())Syntaxelement.findElements(By.xpath("./child::*"))Let us identify the tagname of the sub-elements of element ul in below html 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; public class SubElement{ public static ... Read More

6K+ Views
We can scroll down the page till page end with Selenium webdriver.Selenium cannot directly scroll up or down with its methods. This is done with the Javascript Executor. DOM can interact with the elements with Javascript.Selenium runs the commands in Javascript with the execute_script() method. For scrolling till the page down, we have to pass (0, document.body.scrollHeight) as parameters to the method scrollTo().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 org.openqa.selenium.JavascriptExecutor; public class ScrollTillPageEnd{ 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

5K+ Views
We can wait for the iframe to load completely with Selenium webdriver.First of all we need to identify the iframe with the help iframe id, name, number or webelement. Then we shall use the explicit wait concept in synchronization to wait for the iframe to load.We need to import org.openqa.selenium.support.ui.ExpectedConditions and import org.openqa.selenium.support.ui.WebDriverWait to incorporate expected conditions and WebDriverWait class. We will wait for the iframe to be loaded with the condition frameToBeAvailableAndSwitchToIt.Let us see an html document of a frame.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 org.openqa.selenium.support.ui.WebDriverWait; import org.openqa.selenium.support.ui.ExpectedConditions; public class FrameLoadWait{ public ... Read More

5K+ Views
We can test if an element is focused with Selenium webdriver. This is determined with the help of the activeElement() method. First of all we need to identify the element with help of any of the locators like id, class, name, xpath or css.Syntaxdriver.switchTo().activeElement();Let us consider the below edit box and check if it is focused.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; public class ElementFocussed{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.get("https://www.tutorialspoint.com/index.htm"); // identify ... Read More

3K+ Views
We can find a radio button element by value with Selenium webdriver. A radio button in an html document has a tagname input and it has a type attribute set to radio. We can select a radio button by using the click() method after identifying it.Let us see the html code of a radio button. To identify it with a value attribute we have to use the xpath or css locator.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; public class RadioButnVal{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ... Read More

18K+ Views
We can get the page title with Selenium webdriver. The method getTitle() is used to obtain the present page title and then we can get the result in the console.Syntaxt = driver.getTitle();Let us find the title of the current page. We shall get About Careers at Tutorials Point – Tutorialspoint as output.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; public class PageTitle{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.get("https://www.tutorialspoint.com/about/about_careers.htm"); // getTitle() to obtain page title ... Read More

5K+ Views
We can obtain the option selected in a dropdown with Selenium webdriver. The first_selected_option method fetches the option selected in the dropdown. Once the option is returned we need to apply a text method to get option text.Let us consider the select dropdown Continents and fetch its selected item −Examplefrom selenium import webdriver from selenium.webdriver.support.select import Select import time driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) driver.get("https://www.tutorialspoint.com/selenium/selenium_automation_practice.htm") # identify dropdown s = Select(driver.find_element_by_xpath("//select[@name='continents']")) #select by option index s.select_by_index(4) #get selected item with method first_selected_option o= s.first_selected_option #text method for selected option text print("Selected option is: "+ o.text) driver.close()OutputRead More

3K+ Views
We can select an option from the dropdown list with Selenium webdriver. The Select class is used to handle static dropdown. A dropdown is identified with the tag in an html code.Let us consider the below html code for tag.We have to import org.openqa.selenium.support.ui.Select to work with methods under Select class in our code. Let us see some of the Select methods−selectByVisibleText(arg) – An option is selected if the text visible on the dropdown is the same as the parameter arg passed as an argument to the method.Syntaxsel = Select (driver.findElement(By.id ("option")));sel.selectByVisibleText ("Selenium");selectByValue(arg) – An option is selected ... Read More

612 Views
We can simulate HTML5 drag and drop with Selenium webdriver. This is a feature that gets implemented if an element is dragged from its position and dropped on another element in another position.Actions class in Selenium is used for taking care of this functionality. The drag_and_drop(source, target) is the available method under Actions class for carrying out this task. We have to import from selenium.webdriver import ActionChains to our code to use this method of Actions class.Let us take the two elements and try to drag the first element on to the second element.Examplefrom selenium.webdriver import ActionChains from selenium import ... Read More

4K+ Views
We can find an element by attributes with Selenium webdriver. There are multiple ways to do this. We can use the locators like css and xpath that use attributes and its value to identify an element.For css selector, theexpression to be used is tagname[attribute='value']. There are two types of xpath – absolute and relative. The xpath expression to be used is //tagname[@attribute='value'], the tagname in the expression is optional. If omitted, the xpath expression should be //*[@attribute='value'].Let us consider an element with input tagname. It will be identified with xpath locator with id attribute (//input[@id='txtSearchText']).Examplefrom selenium import webdriver driver = ... Read More