Python + Selenium Jump Pit Tour (first play)

Source: Internet
Author: User

Even if you are proficient in selenium, the most testing staff is to locate the problem.


First Pit:

to locate the page, HTML nesting appears, which is ifrmae. This is something that can be found intuitively in the HTML code page. It is actually referring to a sub-page in a page. This causes us to use XPath or CSS to locate the element when it is not found directly. This time we need to use a new thing to locate her, the idea is basically: the first step, from the parent page to the child page; The second step is to locate the element in the sub-page; The third step is to return to the parent page (this depends on where the individual needs to be, exactly where it needs to be).

The implementation of the first step requires a method: Switch_to_frmae. Refer to the code for specific usage. Here, I must remind you that Switch_to_frmae does not necessarily work, because version issues may need to become switch_to.frmae. A ' _ ', a '. ', this pit I've been climbing for a long time.

The second step is relatively simple, and we can use Firebug to copy the XPath or CSS path. It is worth noting that this time the path is from the sub-page, and the parent page has nothing to do, if you want to use id,class and so on positioning, it should also be possible (of course I did not try, I am not responsible for this sentence).

The third step, return, when we do not need to locate in this sub-page need to exit, this requires a new method,

Switch_to.default_content ().    The specific content can be Baidu or reference my Code map.        At this point, the first pit jumps out. When positioning elements, be sure to pay attention to element or elements, a singular, a complex number, the meaning is really different too big. When you find_element_by_id (' P ') is just an element of id = ' P ', find_elements_by_id (' P ') is actually a bunch of id = ' P ' consisting of a list. Remember that you want one or more elements, remember.
I posted the code, is my test account password login QQ mailbox When the problem, this problem is not the code, may be because of network or other reasons for the problem, when I locate the QQ mailbox ' login ' button, click () always appear ' Server busy words ', start I think is click too fast, I set Time.sleep (3) still so (invisible waiting I did not try, but interested students can try), in order to solve this problem, I can only first click (), then Time.sleep (3), then click (), incredibly successful.


This article is from the "Test Technical Questions Summary" blog, please be sure to keep this source http://xiaowangu.blog.51cto.com/5707515/1954231

Python + Selenium Jump Pit Tour (first play)

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.