Debomita Bhattacharjee

Debomita Bhattacharjee

590 Articles Published

Articles by Debomita Bhattacharjee

Page 43 of 59

How to get all descendants of an element using webdriver?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 18-Sep-2020 2K+ 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
Debomita Bhattacharjee
Updated on 18-Sep-2020 12K+ 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 selected option using Selenium WebDriver with Java?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 18-Sep-2020 17K+ 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
Debomita Bhattacharjee
Updated on 18-Sep-2020 3K+ 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()Output

Read More

Locating child nodes of WebElements in selenium.

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 18-Sep-2020 21K+ 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
Debomita Bhattacharjee
Updated on 18-Sep-2020 7K+ 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
Debomita Bhattacharjee
Updated on 18-Sep-2020 511 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
Debomita Bhattacharjee
Updated on 18-Sep-2020 8K+ 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
Debomita Bhattacharjee
Updated on 18-Sep-2020 14K+ 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 select a drop-down menu option value with Selenium (Python)?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 18-Sep-2020 17K+ 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
Showing 421–430 of 590 articles
« Prev 1 41 42 43 44 45 59 Next »
Advertisements