Found 871 Articles for Automation Testing

How to get all descendants of an element using webdriver?

Debomita Bhattacharjee
Updated on 18-Sep-2020 09:49:52

1K+ Views

We can get all descendants of an element 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 descendants with the findElements(By.xpath()) method.We can find the descendants from the parent element, by localizing it with the parent and then passing ( .//*) as a parameter to the findElements(By.xpath())Syntaxelement.findElements(By.xpath(".//*"))Let us identify the tagname of the descendants of ul element 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 DescendantElements{    public ... Read More

Get value of an input box using Selenium (Python)

Debomita Bhattacharjee
Updated on 18-Sep-2020 09:41:33

10K+ Views

We can get the value of an input box with Selenium webdriver. The get_attribute() method is capable of obtaining the value we have entered in an input box. To get the value, we have to pass value as a parameter to the method.First of all, we have to identify the input box with the help of any of the locators like id, class, name, css or xpath. Then we have to type some values inside it with the send_keys() method.Let us consider the below input box where we shall enter some texts - Selenium Python and then fetch the value ... Read More

How to get attribute of element from Selenium?

Debomita Bhattacharjee
Updated on 18-Sep-2020 09:36:56

8K+ Views

We can get the attribute of element in Selenium webdriver. The getAttribute() method is used to obtain the value of an attribute in an html document. In an html code, attribute and its value appear as a key value pair.Some of the commonly known html attributes are disabled, alt, id, href, style, title and src. The value of the attribute that we want to fetch is passed as an argument to the method.Let us consider an html code, for which we shall obtain the src attribute. The value of the src attribute should be /about/images/logo.png.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; ... Read More

How to get selected option using Selenium WebDriver with Java?

Debomita Bhattacharjee
Updated on 18-Sep-2020 09:34:21

14K+ Views

We can get a selected option in a dropdown in Selenium webdriver. The method getFirstSelectedOption() returns the selected option in the dropdown. Once the option is fetched we can apply getText() method to fetch the text.Let us consider the below dropdown Continents get its selected item−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.Select public class SelecedItem{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String u =" https://www.tutorialspoint.com/selenium/selenium_automation_practice.htm"driver.get(u);       driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);       // identify element   ... Read More

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

323 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

Advertisements