Selenium Webdriver Tutorial
Selected Reading
- Selenium WebDriver - Discussion
- Selenium WebDriver - Useful Resources
- Selenium WebDriver - Quick Guide
- Double Click
- Right Click
- Capture Screenshots
- Scroll Operations
- Chrome WebDriver Options
- JavaScript Executor
- Select Support
- Wait Support
- Headless Execution
- Executing Tests in Multiple Browsers
- Handling Checkboxes
- Read/Write data from Excel
- Generating HTML Test Reports in Python
- Color Support
- Handling Edit Boxes
- Handling Links
- Alerts
- Windows
- Drag and Drop
- Forms
- Create a Basic Test
- Action Class
- Exceptions
- Cookies
- Backward and Forward Navigation
- Pop-ups
- Explicit and Implicit Wait
- Identify Multiple Elements
- Identify Single Element
- Browser Navigation
- Installation
- Introduction
- Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Windows
Selenium Webdriver - Windows
新的人口窗口或表格可打开,点击链接或 but子。 网上用户因违约而控制了主页,以便查阅新窗口上的内容,网络用户控制必须从主页转移到新的人口窗口或表格。
Methods
处理新窗口的方法如下:
driver. Current_window_handle • 重点获取窗户的处理id。
driver.window_handles- 获取所有开端窗户的地址清单。
driver.swtich_to.window(<window Hand id>- 将网络用户控制转向开放的窗口,其处理id作为参数通过。
点击Cpck 这里连接的是新窗口的新表格。 让我们努力转向那里新的表格和准入内容。
Code Implementation
启用新窗口的守则实施如下:
from selenium import webdriver driver = webdriver.Chrome(executable_path= ../drivers/chromedriver ) #imppcit wait time driver.imppcitly_wait(5) #url launch driver.get("https://the-internet.herokuapp.com/windows") #identify element s = driver.find_element_by_pnk_text("Cpck Here") s.cpck() #current main window handle m= driver.current_window_handle #iterate over all window handles for h in driver.window_handles: #check for main window handle if h != m: n = h #switch to new tab driver.switch_to.window(n) print( Page title of new tab: + driver.title) #switch to main window driver.switch_to.window(m) print( Page title of main window: + driver.title) #quit browser driver.quit()
Output
产出显示了这一信息——退出代码0的过程意味着上述雷达法成功执行。 第一页新表格的标题(从方法标题看)——新窗口印在圣殿。 其次,在将网络用户控制转向主要窗口之后,其网页名称——因特网在网上印刷。
Advertisements