In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Before officially creating a test project, it is necessary to describe in detail how to find page elements, of course, according to the properties of page elements, we must all be familiar with commonly used browsers such as Chrome and Firefox, generally select the element you want to view on the web page and then right-click the review element to see the attributes of the element, know how these element attributes are combined with webdriver? Let's introduce the method of webdriver locate elements, which uses the findElement (By.** ()) keyword to locate elements in webdriver.
The first fastest and most convenient method: By ID
Usually, an element on a web page will have a unique identified ID, just like our × × ×, which is used to uniquely identify an element. WebDriver uses this method to discover the syntax of the element is very simple.
Driver.findElement (By.id ("*")); here, as long as you know the corresponding id of the element, you can find the element. Some people may say, how do I know id? You can directly check the page elements in the html code to see the id of the elements you want, such as Baidu page search box corresponding to the html code is: here you can clearly see that the text box id is kw, the corresponding discovery element code should be: driver.findElement (By.id ("kw")); Note: not all elements have id, this should be based on but the development of the design.
The second method: By Name
Driver.findElement (By.name ("*")); here, as long as you know the name of the corresponding element, you can successfully find the element. Take the search box on the home page of Baidu as an example, the name of the search box is wd, and the corresponding code should be driver.findElement (By.name ("wd")). Of course, not all elements have name.
The third method: By xpath
Driver.findElement (By.xpath ("*")); here you can locate elements through the xpath of elements. If you are interested in xpath, you can visit http://www.w3school.com.cn/xpath/ to learn about it. Without introduction here, here are some ways to find elements using xpath even if you don't know the syntax of xpath:
# 1 use firefox's xpath plug-in to search for xpath in add-on, and then select xpath checker. After installation, you can use xpath. For example, if I want to get the XPath value of Baidu homepage logo, just move the cursor over the picture and right-click view xpath to get the xpath value: id ('lg') / x:img, so the corresponding code here should be: driver.findElement ("id (' lg') / x:img")
# 2 using chrome's xpath plug-in, this plug-in feels easier to use than the plug-in under firefox, and the probability of error is much smaller. After the plug-in is successfully installed for PsychoXpath: https://chrome.google.com/webstore/detail/psychoxpath/bpnigkcdmnofjkmojlopmelmhgpbndog, right-click the corresponding element and you can choose the absolute path (Absolute). This absolute path is not recommended here, and the second (short) is highly recommended. Of course, you can also highlight the element. It's definitely fun to try it yourself.
After getting the corresponding xpath, you can replace the value with driver.findElement (By.xpath (")).
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 248
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.