Found 455 Articles for Software Testing

How to clear the text entered in Selenium with python?

Debomita Bhattacharjee
Updated on 29-Jul-2020 07:53:15

19K+ Views

We can enter text on any field in Selenium. After entering the text, we may need to remove or clear the text we entered in that field. This interaction with the web elements can be achieved with the help of clear() method.Thus a clear() method is used to clear or reset an input field belonging to a form/ edit box. It replaces the text content on that particular element of the page.Syntaxdriver.find_element_by_xpath("//input[class ='gsc-search']").clear()ExampleCode Implementation with clear() method.from selenium import webdriver #browser exposes an executable file #Through Selenium test we will invoke the executable file which will then #invoke actual browser ... Read More

How to use a click() method in Selenium with python?

Debomita Bhattacharjee
Updated on 29-Jul-2020 07:51:58

1K+ Views

While working on an application and navigating to different pages or different sections of a page, we need to click on various UI elements on a page like a link or a button. All these are performed with the help of click() method.Thus a click() method typically works with elements like buttons and links.Syntax driver.find_element_by_xpath("//button[id ='value']").click()ExampleCoding Implementation with click() method for clicking a link.from selenium import webdriver #browser exposes an executable file #Through Selenium test we will invoke the executable file which will then #invoke #actual browser driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") # to maximize the browser window driver.maximize_window() #get method to launch ... Read More

How to enter values in an edit box in Selenium with python?

Debomita Bhattacharjee
Updated on 29-Jul-2020 07:48:00

777 Views

We can enter values in an edit box in Selenium with the help of the methods listed below −Using the send_keys method.This method can send any text to an edit box or perform pressing keys with the help of Keys class.Using the Javascript executor.Javascript Document Object Model can work with any of the elements on the page. Javascript works on the client side and performs actions on the web page. Selenium can execute a Javascript script with the help of execute_script() method. We can enter values on any edit box with the help of this method.ExampleCode Implementation with send_keys method.from ... Read More

How to fetch values from a webelement in Selenium with python?

Debomita Bhattacharjee
Updated on 29-Jul-2020 07:46:12

759 Views

We can fetch values from a webelement in Selenium with the help of the methods listed below −Using the text method.This will give the inner text of the webelement. It basically gives us the visible text on the screen and its sub element if any. This method will also remove all the forward and backward white spaces.Using the Javascript executor.Javascript Document Object Model can work with any of the elements on the page. Javascript works on the client side and performs actions on the web page. Selenium can execute a Javascript script with the help of execute_script() method. We can ... Read More

How to click on a link in Selenium with python?

Debomita Bhattacharjee
Updated on 29-Jul-2020 07:44:31

6K+ Views

We can click on a link on page with the help of locators available in Selenium. Link text and partial link text are the locators generally used for clicking links. Both these locators work with the text available inside the anchor tags.Link Text – The text within the anchor tag is matched with the element to be identified. With this, the first matching element is returned. In case of not matching, NoSuchElementException is thrown.Partial link Text – The partial text within the anchor tag is matched with the element to be identified. With this, the first matching element is returned. ... Read More

How will you travel from child to parent with xpath in Selenium with python?

Debomita Bhattacharjee
Updated on 29-Jul-2020 07:41:59

10K+ Views

We can identify a parent from its children in DOM with the help of xpath. There are situations where we have dynamic attributes for the parent node in html but the child nodes have unique static attributes for identification.This can be achieved with the help of relative xpath along with the parent xpath axe. Method.Syntax driver. find_element_by_xpath("//input[@id='job']/parent::div")ExampleCode Implementation for child to parent traversal.from selenium import webdriver #browser exposes an executable file #Through Selenium test we will invoke the executable file which will then #invoke #actual browser driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") # to maximize the browser window driver.maximize_window() #get method to launch the ... Read More

What is xpath in Selenium with python?

Debomita Bhattacharjee
Updated on 29-Jul-2020 07:40:05

4K+ Views

Xpath is one the locators used in Selenium to identify elements uniquely on a web page. It traverses the DOM to reach the desired element having a particular attribute with/without tagname.The xpath can represented by the ways listed below −//tagname[@attribute='value']//*[@attribute='value']The xpath can be created by the following methods −OR & AND expression.following- sibling expression.parent.child.ancestor.self.descendant.starts-with()ends-with()text()preceding.There are two types of xpath – absolute and relative.Relative xpath – This path begins from any part of the DOM html. It is represented by double slash // and helps to identify elements from any part of the web page and the xpath expression is not ... Read More

What are the differences between xpath and css in Selenium with python?

Debomita Bhattacharjee
Updated on 29-Jul-2020 07:38:10

9K+ Views

Both xpath and css are one the most frequently used locators in Selenium. Though there are other locators like id, name, classname, tagname, and link text and so on, xpath and css are used when there are no unique attributes available to identify the elements.There are some differences between xpath and css listed below −Xpath allows bidirectional flow which means the traversal can be both ways from parent to child and child to parent as well. Css allows only one directional flow which means the traversal is from parent to child only.Xpath is slower in terms of performance and speed. ... Read More

How to identify nth element using xpath in Selenium with python?

Debomita Bhattacharjee
Updated on 29-Jul-2020 07:34:22

3K+ Views

There are multiple ways of building a customized xpath. In case we need to identify nth element we can achieve this by the ways listed below.position() method in xpath.Suppose we have two edit boxes in a page with similar xpath and we want to identify the first element, then we need to add the position()=1.Syntax −driver.find_element_by_xpath("//input[@type='text'][position()=1]")square bracket addition with braces to indicate index.Suppose we need to reach the third row of the table and the customized xpath for that row should be indicated with the help of [3] expression.Syntax −driver.find_element_by_xpath("//table/tbody/tr[2]/td[2]")ExampleCode Implementation with position()from selenium import webdriver #browser exposes an executable ... Read More

Explain some of the ways of creating customized css in Selenium with python?

Debomita Bhattacharjee
Updated on 29-Jul-2020 07:32:08

236 Views

The css is one of the important locators in Selenium. A customized css can be developed with the help of attributes like id, classname and by the combination of tagname and html attributes.The ways of creating a css are listed below −Using a class name html attribute.This will select the web element of that particular class represented by (.)classname.Syntax −driver. find_element_by_css_selector(".name")Here name is the value of the attribute class.Using an id html attribute.This will select the web element of that particular id represented by (#) id.Syntax−driver. find_element_by_css_selector("#search")Here search is the value of the attribute id.Using a combination of tagname and ... Read More

Advertisements