selenium2+python3.6 Combat (Eight): The location of the drop-down menu error, how to solve? Locate with Select or XPath.

Source: Internet
Author: User
Tags xpath

At the login interface, sometimes there are several different roles, and the information targeted to different roles is not the same. Query data know the elements of the anchor drop-down box are available in two ways: XPath and select.

But when using the XPath to locate, the user navigates to, the login time is called the administrator, is the expense brain. After several setbacks, finally solved.

1. About user XPath positioning: recording the login process with the Selenium IDE, viewing the code only to find and not locate the user, but directly enter the password to log in. This reminds me that user is the default users, when entering the login interface, the user is the default page, so you can omit to locate this step, but this is not the solution of the fundamental method. Using the IDE to record the process and then review the code comparison can be used as a way to troubleshoot problems later.

2. Use Select to locate

On the Internet to see some information that XPath is not very good for the dropdown box positioning, such as when the code changes the order of the options, then need to re-write the script, which is very unstable. And I used a few select to locate, referring to the code on the Internet, how are not successful, every time the error.

Before you know what to look for with select:

1) Import the Select module First, 2) Select is only valid for the contents of the <select> tag, 3) Navigate to the <select> tab, and then use the text of index, value, or option to determine the options.

Here is the code that I ran successfully:

There is no problem with the pro-test, just remember that the 3 points noted above can be successful.

Attach the non-<select> tag drop-down menu location method:

selenium2+python3.6 Combat (Eight): The location of the drop-down menu error, how to solve? Locate with Select or XPath.

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.