python - 如何使用 selenium python 打开新窗口

标签 python selenium selenium-webdriver selenium-chromedriver

我正在网站上进行自动化。

我在此网站上进行搜索,您的结果返回一个链接供我访问,单击它以打开一个新选项卡,但我想打开一个新窗口

这是我点击链接的代码

WebDriverWait(self.browser, timeout=60).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="tabelaResultado"]/div[1]/table/tbody[1]/tr/td[1]/span/a'))).click()

我尝试使用 SHIFT 键盘快捷键

WebDriverWait(self.browser, timeout=60).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="tabelaResultado"]/div[1]/table/tbody[1]/tr/td[1]/span/a'))).send_keys(Keys.SHIFT).click()

但是我有一个结果错误

AttributeError: 'NoneType' object has no attribute 'click'

有没有办法配置 Chrome,以便每次单击链接时都会打开一个新窗口?

from selenium.webdriver.chrome.options import Options

最佳答案

我认为你必须这样写:发送ShiftEnter:

WebDriverWait(self.browser, timeout=60).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="tabelaResultado"]/div[1]/table/tbody[1]/tr/td[1]/span/a'))).send_keys(Keys.SHIFT,Keys.ENTER)

关于python - 如何使用 selenium python 打开新窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58750082/

相关文章:

python - ValueError:未知标签类型: 'continuous'

python - 在Python中重写unittest.TestCase的init是不是非常规

python - 接收属性错误 'FirefoxBinary'对象没有属性 '_get_firefox_output'

python - 当 insideText 包含前导和尾随空白字符时,如何使用 Selenium 和 Python 定位并单击该元素

selenium - 自动关闭 Apple id 验证弹出窗口

safari - Selenium - 禁用弹出窗口阻止程序

python - Plotly 3D 绘图注释

python - 如何使用 Cython 将 python 函数作为参数传递给 c++ 函数

ruby-on-rails - 超时::Selenium/Capybara/Cucumber 出错

ruby - Selenium 在 Ruby capybara 测试中指定 chromedriver.exe 的路径