I have used most of the element locator while Testing with selenium but very low frequently used 'TagName' locator. Please give and example.
相关问题
- Selecting an item from a combo box selenium driver
- Selenium in Java is not finding element when using
- How to send text to the search field through Selen
- What is the difference in “find_element_by_xpath”
- Cloudflare and Chromedriver - cloudflare distingui
Now supposing, software web element do not have any ID or Class Name then how to locate that element in selenium WebDriver ? Answer is there are many alternatives of selenium WebDriver element locators and one of them is Locating Element By Tag Name.
Locating Element By Tag Name is not too much popular because in most of cases, we will have other alternatives of element locators. But yes if there is not any alternative then you can use element's DOM Tag Name to locate that element in webdriver.
Here you can select the tagname as a locator like:
Also importantly, The
tagName
locating strategy can be used to get or fetch all the links in a webpage and print them to console. Try this:we use the actual name of the tag like for anchor and for table and input for . This helps to get all the elements with a given tag name. Example: to select first element of given input
Thanks to the deprecation of By.tagName you should use By.css for @Shah 's answer....