Web Automation 6-selenium Multi-window switch and JS dialog box processing

Source: Internet
Author: User

1. Multi-Window switching

Browser.window_handles Show All Handles

Browser.current_window_handle Show Current handle

Browser.switch_to_window (browser.window_handles[1]) toggle Handle

2. JS dialog box processing

alter = Browser.find_element_by_xpath ('//*[@id = "Topguideloginform"]/div[4]/button '). Click ()

Switch_to_alert () cut to alter returns an Alter object

Alter.accept () Confirm

Alter.dismiss () Cancel

Send_keys () have input box to use, otherwise error

#coding =utf-8
from Selenium import webdriver
Import Time
Browser = Webdriver. Chrome ()
Browser.get (' http://bbs.tianya.cn/#loginAction ')
Time.sleep (2)
browser.find_element_by_id ("vwriter"). Send_keys ("Zhang")
Time.sleep (1)
browser.find_element_by_id ("Vpassword"). Send_keys ("1234526526672")
Time.sleep (2)
Browser.find_element_by_xpath ('//*[@id = "Topguideloginform"]/div[4]/button '). Click ()
Time.sleep (1)
alter = Browser.switch_to_alert ()
Time.sleep (1)
Alter.dismiss ()

Web Automation 6-selenium Multi-window switch and JS dialog box processing

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.