我有一个 python 脚本设置为打开 10 个选项卡,并在每个选项卡上加载一个网页。我现在需要做的是让它每 30 秒在这些选项卡之间旋转。基本上,在全部加载后,我只需要每 30 秒按一次 Ctrl+Tab,这样它就会旋转并充当幻灯片放映。所有提示?from selenium import webdriverfrom selenium.webdriver.chrome.options import Optionsfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECusernameStr = 'username'passwordStr = 'password'options = Options()options.add_argument('--kiosk')options.add_argument('disable-infobars')driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\Users\username\Desktop\chromedriver.exe')driver.get('http://website.com')# fill in username and hit the next buttonusername = driver.find_element_by_id('username')username.send_keys(usernameStr)password = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, 'password')))password.send_keys(passwordStr)nextButton = driver.find_element_by_class_name('emp-submit')nextButton.click()#second tabdriver.execute_script("window.open('about:blank', 'tab2');")driver.switch_to.window("tab2")driver.get('http://website.com')#third tabdriver.execute_script("window.open('about:blank', 'tab3');")driver.switch_to.window("tab3")driver.get('http://website.com')#fourth tabdriver.execute_script("window.open('about:blank', 'tab4');")driver.switch_to.window("tab4")driver.get('http://website.com')
1 回答
呼啦一阵风
TA贡献1802条经验 获得超6个赞
我将driver.switch_to.window用于此任务,例如:
while True:
Windows = driver.window_handles
for window in Windows:
driver.switch_to.window(window)
time.sleep(30)
添加回答
举报
0/150
提交
取消