Found 466 Articles for Selenium

Select iframe using Python and Selenium

Debomita Bhattacharjee
Updated on 18-Sep-2020 08:00:45
We can select iframe with Selenium webdriver. An iframe is identified with a tag in an html document. An iframe is an html document containing elements which resides inside another html document.Let us see a html document of a frame.The following methods help to switch between iframes−switch_to.frame(args) – The frame index is put as an argument to the method. The starting index of iframe is 0.Syntax−driver.switch_to.frame(0), switching to the first iframe.switch_to.frame(args) - The frame name or id is put as an argument to the method.Syntax−driver.switch_to.frame("nm"), switching to the iframe with name nm.switch_to.frame(args) - The frame webelement is put as ... Read More

How to select element using XPATH syntax on Selenium for Python?

Debomita Bhattacharjee
Updated on 18-Sep-2020 07:54:10
We can select elements using xpath with Selenium webdriver. Xpath is one of the most important locators. There are two types of xpath. They are known as absolute [starting from parent node in DOM] and relative xpath [starting from anywhere in DOM].The xpath syntax is − //tagname[@attribute='value'] or //*[@attribute='value'].Let us consider the html code of an element that we shall identify with the help of xpath−The xpath expression is //input[@name='firstname'] or //*[@name='firstname'].Examplefrom selenium import webdriver 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 element with xpath l = driver.find_element_by_xpath("//input[@name='firstname']") l.send_keys("Python") driver.quit()OutputRead More

How to get css class name using Selenium?

Debomita Bhattacharjee
Updated on 18-Sep-2020 07:43:59
We can get the css class name of an element with Selenium webdriver. To obtain the class name attribute of an element in the html document, we have to use the getAttribute() method. Then the class value is passed as a parameter to the method.Let us consider the below html code with class attribute.The class attribute is having the value as gsc-input. This can be obtained with the help of getAttribute() method.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 GetClssAttribute{    public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = ... Read More

How to delete default values in text field using Selenium?

Debomita Bhattacharjee
Updated on 18-Sep-2020 06:56:36
We can delete default values in the text field with Selenium webdriver. There are multiple ways to do this. We can use the clear() method which resets value present already in edit box or text area field.We can use the Keys.chord() method along with sendKeys(). The Keys.chord() method helps to press multiple keys simultaneously. It accepts the sequence of keys or strings as a parameter to the method.To delete default values, it takes, Keys.CONTROL, "a" as parameters. This string is then sent as a parameter to the sendKeys() method. Finally, we have to pass Keys.DELETE to the sendKeys() method.Let us consider ... Read More

How to click on across browsers using Selenium Webdriver?

Debomita Bhattacharjee
Updated on 18-Sep-2020 06:50:58
We can click on a button with across browsers with Selenium webdriver. First of all we need to identify the element with the help of locators like xpath or css, then apply sendKeys() method where the path of the file to be uploaded is passed.Let us see the html code of an element with input type as file. The corresponding representation of the element on the screen shall be.For working with this element we need to first interact with the Browse button and also the path of the file to be uploaded should be valid.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import ... Read More

Python selenium browser driver.back().

Debomita Bhattacharjee
Updated on 18-Sep-2020 06:40:29
We can navigate back in the browser with Selenium webdriver. There are multiple ways to achieve this. The back() method is used to move back to the prior browser page. This method only is applicable if we jump from webpage to another.We can also move back in the browser with the help of a Javascript Executor in Selenium. It has the execute_script() method which allows Selenium to run Javascript commands. We have to execute the Javascript command window.history.go(-1) to go back to the previous page.Examplefrom selenium import webdriver driver = webdriver.Chrome (executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) #launch a webpage driver.get("https://www.tutorialspoint.com/about/about_careers.htm") print("Current Page title: ... Read More

Using Selenium Web Driver to retrieve value of a HTML input.

Debomita Bhattacharjee
Updated on 18-Sep-2020 06:34:35
We can get the value of a HTML input with Selenium webdriver. This is achieved with the help of the getAttribute() method. To retrieve the value of the field with tagname input, we have to pass the value as parameter to the getAttribute() method.Let us consider an html code for a html input.We have no value attribute for the field in the DOM. However we shall get the field value as displayed with getAttribute() method.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class InputVal{    public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");   ... Read More

How to hold key down with Selenium?

Debomita Bhattacharjee
Updated on 18-Sep-2020 06:28:26
We can hold a key down with Selenium webdriver. We mostly utilize the CONTROL/SHIFT/ALT keys to hold down and then click on other keys. So, only mentioning the modifier keys like keys.CONTROL/ keys.SHIFT or Keys.ALT is not sufficient.To hold down a key simultaneously while another key is being pressed, we use the keyDown() and keyUp() methods. Both these methods accept the modifier key as a parameter.The action of these two methods on a key yields a special functionality of a key. All these methods are a part of Actions class in Selenium. We have to add the import org.openqa.selenium.interactions.Actions package ... Read More

Key press in (Ctrl+A) Selenium WebDriver.

Debomita Bhattacharjee
Updated on 18-Sep-2020 06:12:55
We can perform key press of (CTRL+A) with Selenium Webdriver. There are multiple ways to do this. We can use the Keys.chord() method to simulate this keyboard action.The Keys.chord() method helps to press multiple keys simultaneously. It accepts the sequence of keys or strings as a parameter to the method. To press CTRL+A, it takes, Keys.CONTROL, "a" as parameters.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class PressCtrlA{    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";     ... Read More

Find elements inside forms and iframe using Java and Selenium WebDriver.

Debomita Bhattacharjee
Updated on 18-Sep-2020 06:08:24
We can find elements inside form and iframe with Selenium webdriver. A form in an html document is represented by atag. A form may contain multiple elements inside it. A form can be submitted with a submit() or a click() method.Let us see a form with fields email and password.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 FormElements{    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.linkedin.com/";       driver.get(url);       driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS);       // ... Read More
Advertisements