简体   繁体   English

Python - 使用 Selenium WebDriver 在新的 Chrome 选项卡中打开链接?

[英]Python - Open a link in new Chrome tab with Selenium WebDriver?

I would like to have a URL open in a new tab and closing itself rather than opening in front of the user as it currently stands.我希望在新选项卡中打开一个 URL 并关闭它自己,而不是像目前那样在用户面前打开。 I want it to be a discrete as possible.我希望它尽可能离散。

Here is the python code I have so far that works, but brings the window to the front:这是我到目前为止有效的python代码,但将窗口带到了前面:

def extract(self, id, pass):
    chrome_dir_path = '/Users/<user>/Downloads/chromedriver'
    driver = webdriver.Chrome(chrome_dir_path)
    driver.implicitly_wait(5)
    driver.maximize_window()
    driver.get('https://<URL>')
    username = driver.find_element_by_id('user')
    username.send_keys(USER)
    password = driver.find_element_by_id('password')
    password.send_keys(PASS)
    driver.find_element_by_name('remUID').click()
    python_button = driver.find_element_by_class_name('button')
    python_button.click()

无头运行解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Selenium webdriver在python中的chrome编码中打开一个新选项卡 - Selenium webdriver open a new tab in chrome coding in python 在Python中使用Selenium WebDriver在新标签页/窗口中打开链接 - Using Selenium WebDriver in Python to Open Link in New Tab/Window 由python webdriver在chrome浏览器中的selenium新选项卡 - selenium new tab in chrome browser by python webdriver Python + Selenium WebDriver:在新标签页中打开URL - Python + Selenium WebDriver: open URL in new tab 如何使用python和selenium在新选项卡中打开链接 - How to open a link in a new tab with python and selenium python selenium 在新标签页中打开链接并继续 session 在新标签页中 - python selenium open link in new tab and continue session in new tab Selenium不会在新标签页(Python和Chrome)中打开新的URL - Selenium won't open a new URL in a new tab (Python & Chrome) 如何使用 Control + Click of Selenium Webdriver 在同一窗口的新选项卡中的主选项卡中打开嵌入在 webelement 中的链接 - How to open a link embeded in a webelement with in the main tab, in a new tab of the same window using Control + Click of Selenium Webdriver 如何使用 Python 中的 Selenium-chromeDriver 在 Chrome 中打开新标签页 - How to open new tab in Chrome with Selenium-chromeDriver in Python 在 Selenium 自动 chrome 中打开 chrome 新选项卡 - Open chrome new tab in Selenium automated chrome
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM