码迷,mamicode.com
首页 > 其他好文 > 详细

wen自动化之浏览器的窗口切换

时间:2019-03-21 01:24:48      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:exp   new   expected   driver   bdr   浏览器   wait   点击   submit   

from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
driver = webdriver.Chrome()
driver.get("https://www.baidu.com/")
driver.maximize_window()
window = driver.window_handles
print("当前窗口:",driver.current_window_handle)
driver.find_element_by_xpath(//input[@id="kw"]).send_keys("柠檬班")
driver.find_element_by_xpath(//input[@id="su"]).submit()
webelenment = (By.XPATH,//div[@tpl="tieba_general"]//a[text()="吧_百度贴吧"])
time.sleep(2)
WebDriverWait(driver,20).until(EC.presence_of_element_located(webelenment))
driver.find_element_by_xpath(//div[@tpl="tieba_general"]//a[text()="吧_百度贴吧"]).click()
# 判断窗口是否进行切换
WebDriverWait(driver,20).until(EC.new_window_is_opened(window))
# 进行窗口的切换
windows = driver.window_handles
driver.switch_to.window(windows[-1])
print("切换后的窗口",driver.current_window_handle)
# 点击签到操作
wb = (By.XPATH,//a[@title="签到"])
WebDriverWait(driver,20).until(EC.presence_of_element_located(wb))
time.sleep(2)
driver.find_element_by_xpath(//a[@title="签到"]).click()

 

wen自动化之浏览器的窗口切换

标签:exp   new   expected   driver   bdr   浏览器   wait   点击   submit   

原文地址:https://www.cnblogs.com/666666pingzi/p/10568884.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!