Found 719 Articles for Testing Tools

How to get coordinates or dimensions of element with Selenium Python?

Debomita Bhattacharjee
Updated on 18-Sep-2020 09:30:30

2K+ Views

We can get coordinates or dimensions of elements with Selenium webdriver. Each of the elements have .size and .location properties which give the x, y coordinates and height, width of the element in the form of a dictionary.Syntax −loc = element.locations = element.sizeLet us consider an element for which we shall find coordinates and dimensions−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 element l= driver.find_element_by_xpath("//img[@class='tp-logo']") #get x, y coordinates loc = l.location #get height, width s = l.size print(loc) print(s) driver.close()OutputRead More

How to select an item from a dropdown list using Selenium WebDriver with java?

Debomita Bhattacharjee
Updated on 18-Sep-2020 09:26:08

2K+ Views

We can select an item from a dropdown list with Selenium webdriver. The Select class in Selenium is used to work with dropdown. In an html document, the dropdown is described with the tag.Let us consider the below html code for tag.For utilizing the methods of Select class we have to import org.openqa.selenium.support.ui.Select in our code. Let us see how to select an item with the Select methods−selectByVisibleText(arg) – An item is selected based on the text visible on the dropdown which matches with parameter arg passed as an argument to the method.Syntax−select = Select (driver.findElement(By.id ("txt")));select.selectByVisibleText ('Text');selectByValue(arg) ... Read More

Locating child nodes of WebElements in selenium.

Debomita Bhattacharjee
Updated on 18-Sep-2020 09:22:12

19K+ Views

We can locate child nodes of web elements with Selenium webdriver. First of all we need to identify the parent element with help of any of the locators like id, class, name, xpath or css. Then we have to identify the children with the findElements(By.xpath()) method.We can identify the child nodes from the parent, by localizing it with the parent and then passing ( ./child::*) as a parameter to the findElements(By.xpath())Syntax−parent.findElements(By.xpath("./child::*"))Let us identify the text of the child nodes of ul node 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 ChildNodes{   ... Read More

How to find parent elements by python webdriver?

Debomita Bhattacharjee
Updated on 18-Sep-2020 09:14:14

6K+ Views

We can find parent elements with Selenium webdriver. First of all we need to identify the child element with help of any of the locators like id, class, name, xpath or css. Then we have to identify the parent element with the find_element_by_xpath() method.We can identify the parent from the child, by localizing it with the child and then passing (..) as a parameter to the find_element_by_xpath().Syntax−child.find_element_by_xpath("..")Let us identify class attribute of parent ul from the child element li in below html code−The child element with class heading should be able to get the parent element having toc chapters class ... Read More

How can I get the current contents of an element in webdriver?

Debomita Bhattacharjee
Updated on 18-Sep-2020 09:09:28

327 Views

We can get the current contents of an element in Selenium webdriver. For the elements having tagname as we have to use the getAttribute() method and pass the value parameter as an argument to that method to obtain the current contents.For the elements without an input tag we have to use the getText() method to obtain the current contents. First of all we have to identify the element with the help of the locators.Let us try to get the content Selenium inside the edit box and its above text content – You are browsing the best resource for Online ... Read More

How to check if an element is visible with WebDriver?

Debomita Bhattacharjee
Updated on 18-Sep-2020 09:03:11

7K+ Views

We can check if an element exists with Selenium webdriver. There are multiple ways to check it. We shall use the explicit wait concept in synchronization to verify the visibility of an element.Let us consider the below webelement and check if it is visible on the page. There is a condition called visibilityOfElementLocated which we will use to check for element visibility. It shall wait for a specified amount of time for the element 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. We will introduce a try/catch ... Read More

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

Advertisements