我目前正在使用 chrome(selenium) 来为我自动化一些东西。由于某种原因,我无法让 Selenium 打开另一个网页。
def gotoInventory():
#WebDriverWait(driver,5)
inventoryPS = driver.switch_to.window(driver.window_handles[1])
inventoryPS
openInventoryTab = driver.execute_script("window.open('https://sellercentral.amazon.com/inventoryplanning/dashboard','new window')")
openInventoryTab
def loginProton():
#Need to create a new tab to open proton mail
ActionChains(driver).key_down(Keys.CONTROL).send_keys('t').key_up(Keys.CONTROL).perform()
#above code did not work
#also tried browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't')
openProtonTab = driver.execute_script("window.open('https://mail.protonmail.com/login','new window')")
openProtonTab
由于某种原因, Selenium 总是在库存选项卡上打开网页,这不是我想要的。 protonMail 必须在其自己的选项卡上打开,而不是在 list 选项卡上打开。
任何帮助将不胜感激
最佳答案
出现此问题的原因是在两种情况下使用相同的窗口名称,即“新窗口”。您可以尝试在库存和质子案例中使用不同的窗口名称。另请注意,window.open 创建一个浏览器窗口。
关于python - 使用 selenium 打开两个以上选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59705818/