Solve the problem that select frame in Selenium2Library cannot select frame with no name or id or iframe. selenium2library

Source: Internet
Author: User

Solve the problem that select frame in Selenium2Library cannot select frame with no name or id or iframe. selenium2library

The original select_frame function in Selenium2Library (the corresponding keyword is select frame) can select frame based on locator. However, if a frame or iframe has no id and no name, if multiple frames or iframe exist on the page, the original function cannot select the frame or iframe. The reason is that the default locator option of the original function can be unique.


Solution: Modify the select_frame function in Selenium2Library and support the index selection function.

Locate % PythonHome % \ Lib \ site-packages \ Selenium2Library \ keywords \ _ browsermanagement. py

Open it and find the select_frame method.

Modify the code to the following: the modified select_frame function is as follows:

    def select_frame(self, locator, index):        """Sets frame identified by `locator` as current frame if 'locator' is not unique, use index                Key attributes for frames are `id` and `name.` See `introduction` for details about locating elements.        """        if locator.startswith("tag") :            elements = self._element_find(locator, False, True)            element = elements[int(index)]        else:            element = self._element_find(locator, True, True)        self._current_browser().switch_to_frame(element)

In this case, you can select the frame

Select frame Tag = iframe 1

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.