Found 871 Articles for Automation Testing

Checking if element exists with Python Selenium.

Debomita Bhattacharjee
Updated on 18-Sep-2020 08:56:35

13K+ Views

We can check if an element exists with Selenium webdriver. There are multiple ways to achieve this. We can introduce a try / except block. In the except block, we shall throw the NoSuchElementException in case the element does not exist on the page.We can also verify if an element is present in the page, with the help of find_elements() method. This method returns a list of matching elements. We can get the size of the list with the len method. If the len is greater than 0, we can confirm that the element exists on the page.Examplefrom selenium import webdriver ... Read More

How to check if an alert exists using WebDriver?

Debomita Bhattacharjee
Updated on 18-Sep-2020 08:43:21

7K+ Views

We can check if an alert exists with Selenium webdriver. An alert is created with the help of Javascript. We shall use the explicit wait concept in synchronization to verify the presence of an alert.Let us consider the below alert and check its presence on the page. There is a condition called alertIsPresent which we will use to check for alerts. It shall wait for a specified amount of time for the alert after which it shall throw an exception.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.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import ... Read More

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

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

932 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

Advertisements