Webdriver for a simple window switch

Source: Internet
Author: User

Webdriver implementation of a simple window switch can only be simple, because currently in the learning phase, the complex situation has not yet met. Previously wrote about a small demo summary, there are mentioned in the new window to operate the situation, for the next sentence can be done, last represents the final window, with switch_to switch to the last window (that is, the new window) to operate

Dr.switch_to.window Dr.window_handles.last

This general process is not a problem, but very rigid. What if I open n windows during the operation and go back to a window to do the operation? Obviously the above code is not possible, this time still to start with the code above, window_handles in the document to find the explanation is get the window handles of open broswer windows, the return type is an array, That is, it has been recorded as handles[0 from the beginning of opening the first browser window, and so on. If you want to switch to the second one in the N window, leaf out, the code is as follows.

Dr.switch_to.window Dr.window_handles[1]

However, it is important to emphasize that in this process can not close the window, if the switch off will affect the order, resulting in the occurrence of the window element can not find the problem. When it comes to closing windows, the difference between close and quit: Quit is tough, just turn all the windows off, close closes the current window (in Firefox, other browsers may be different, not tried). Switch_to function is very powerful, but the current use of the switch is directly the browser window, the first record this, later encountered later. Do not know because this is too simple or what the situation, the online information about the switch window is too little, there is Java, but Ruby API is completely different from Java, such as Java can be directly used Getwindowhandle () Get a handle to the current window directly, Ruby has no such usage. I am such a rookie is completely out of control, so a code on the things I have to take a long time. Have to admit that they are really weak explosion, the road long to repair the distant, or that sentence, slowly go.

Webdriver for a simple window switch

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.