Found 519 Articles for Selenium

How can I get the href of elements found by partial link text using Selenium?

Debomita Bhattacharjee
Updated on 18-Sep-2020 14:10:17

492 Views

We can get the href of elements found by partial link text with Selenium webdriver. First of all we need to identify the links with help of the find_elements_by_partial_link_text() method.Next to get hold of href of the links we have to use the get_attribute() method and then pass href as a parameter to the method.Let us identify the href attribute of links identified with partial link text Policy in the below page.Examplefrom selenium import webdriver driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) driver.get("https://www.tutorialspoint.com/about/about_careers.htm") #identify links with partial link text l= driver.find_elements_by_partial_link_text("Policy") #iterate links for i in l: #get href from get_attribute() print("Href value ... Read More

Finding an element in a sub-element in Selenium Webdriver.

Debomita Bhattacharjee
Updated on 18-Sep-2020 14:06:39

8K+ 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

How to scroll down the page till page end in the Selenium WebDriver?

Debomita Bhattacharjee
Updated on 18-Sep-2020 14:01:50

5K+ 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

How to wait for iFrames to load completely in Selenium webdriver?

Debomita Bhattacharjee
Updated on 18-Sep-2020 13:58:32

3K+ 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

Test if an element is focused using Selenium Webdriver.

Debomita Bhattacharjee
Updated on 18-Sep-2020 13:41:53

4K+ 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

How to find a radio button element by value using Selenium?

Debomita Bhattacharjee
Updated on 18-Sep-2020 13:37:46

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

Get page title with Selenium WebDriver using Java.

Debomita Bhattacharjee
Updated on 18-Sep-2020 13:29:47

13K+ 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

How to get selected option using Selenium WebDriver with Python?

Debomita Bhattacharjee
Updated on 18-Sep-2020 13:25:05

4K+ 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

How to use select list in selenium?

Debomita Bhattacharjee
Updated on 18-Sep-2020 13:19:12

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

How to simulate HTML5 Drag and Drop in Selenium Webdriver?

Debomita Bhattacharjee
Updated on 18-Sep-2020 12:47:03

465 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

Advertisements