简体   繁体   中英

Python selenium tab feature works fine in Firefox but not in Chrome

I am working on the below script to open multiple website in new tabs. This is working fine in Firefox as expected.

But it is not working in Chrome. It opens a new tab as the second tab, but the second website link opens in the first tab itself. Later again a new tab is opened as the third tab, then the third link opens in the first tab itself. The commented part ( 5 th line ) is how I call the chromedriver.exe.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

browser = webdriver.Firefox()  #Chrome('C:\\data\\books oae\\apex library\\chromedriver') #Firefox() 

browser.get('https://trello.com/login')
time.sleep(10)
emailElem = browser.find_element_by_id('user')
emailElem.send_keys('test123@gmail.com')
passwordElem = browser.find_element_by_id('password')
passwordElem.send_keys('test12345')
passwordElem.submit()

body = browser.find_element_by_tag_name("body")
body.send_keys(Keys.CONTROL + 't')

browser.get('https://todoist.com/Users/showLogin')
time.sleep(10)
emailElem = browser.find_element_by_id('email')
emailElem.send_keys('test123@gmail.com')
passwordElem = browser.find_element_by_id('password')
passwordElem.send_keys('test12345')
passwordElem.submit()

body = browser.find_element_by_tag_name("body")
body.send_keys(Keys.CONTROL + 't')

browser.get('https://asana.com/#login')
time.sleep(10)
emailElem = browser.find_element_by_id('login-email-login-modal')
emailElem.send_keys('test123@gmail.com')
passwordElem = browser.find_element_by_id('login-password-login-modal')
passwordElem.send_keys('test12345')
passwordElem.submit()

Splinter is the answer to your problem. It's a wrapper around Selenium that does all your Display-handling for you. Just by creating new Splinter objects, you open new windows. You can specify if you want them to be Chrome or Firefox.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM