Locate the page element name

Source: Internet
Author: User

Locating elements by name

Take Douban's homepage search box as an example, the HTML code of its search box is as follows:

The Java sample code for finding the search box elements on the Watercress home page by name in Selenium Webdriver is as follows:

The sample code is detailed:

1, use Firefoxdriver to open the Watercress homepage

2, through the name of Q to call the Findelemet () method to find the Watercress home page of the search box element, and saved to the Webelement instance object in the code as follows:

Webelement searchbox = driver.findelement (By.name ("Q"));

3. Enter the string test Douban by Name in the search box and submit for search

Locate the page element name

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.