Found 519 Articles for Selenium

How to select a drop-down menu option value with Selenium (Python)?

Debomita Bhattacharjee
Updated on 18-Sep-2020 08:38:01

16K+ Views

We can select a drop-down menu option value with Selenium webdriver. The Select class in Selenium is used to handle drop-down. In an html document, the drop-down is identified with the tag.Let us see the html structure of a drop-down.For using the methods of Select class we have to import selenium.webdriver.support.select.Select in our code. Let us discuss the methods available to select an option from drop-down−select_by_visible_text (arg) – The arg which is passed as a parameter to the method is selected if it matches with the text which is visible in the dropdown.Syntax−sel = Select (driver.find_element_by_id ("name"))sel.select_by_visible_text ('Visible Text')select_by_value ... Read More

How to get text from each cell of an HTML table using Selenium?

Debomita Bhattacharjee
Updated on 18-Sep-2020 08:30:23

5K+ Views

We can get text from each cell of an HTML table with Selenium webdriver.A tag is used to define a table in an html document. A table consists of rows represented by and columns represented by . The table headers are identified by tag.Let us consider a table from which we will get text from each cell.AUTOMATION TOOLTYPELINNKSeleniumOpen Sourcehttps://www.selenium.org/UFTCommercialUNified Functional TesterRanorexCommercialhttps://www.ranorex.com/TestCompleteCommercialTest CoompleteLet us see the html code representation for the above table−To retrieve the rows count of the table, we will use−List rows =driver.findElements(By.tagName("tr"));int rws_cnt= rows.size();To retrieve the columns count of the table, we will use−List cols ... Read More

How to get entered text from a textbox in selenium?

Debomita Bhattacharjee
Updated on 18-Sep-2020 08:06:50

15K+ Views

We can get the entered text from a textbox in Selenium webdriver. To obtain the value attribute of an element in the html document, we have to use the getAttribute() method. Then the value is passed as a parameter to the method.Let us consider a textbox where we entered some text and then want to get the entered text.If we spy on the element, we will find that there is no value attribute for this element in the html code.After entering text inside that field, we can get the entered text by using the getAttribute() method.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; ... Read More

Select iframe using Python and Selenium

Debomita Bhattacharjee
Updated on 18-Sep-2020 08:00:45

5K+ Views

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

905 Views

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

10K+ Views

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

12K+ Views

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

1K+ Views

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

10K+ Views

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

12K+ Views

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

Advertisements