chrome浏览器中python webdriver的selenium new选项卡 [英] selenium new tab in chrome browser by python webdriver

查看:128
本文介绍了chrome浏览器中python webdriver的selenium new选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在Chrome中打开新标签页.我的要求是打开一个新选项卡,然后执行一些操作,然后关闭此新选项卡,然后返回到旧选项卡. 以下python代码可在Firefox中使用,但不能在Chrome中使用.谁能帮我吗?

I am not being able to open a new tab in chrome. My requirement is to open a new tab do some operation then close this new tab and come back to old tab. The below python code worked in Firefox but not working in Chrome. Could anyone please help me?

ActionChains(driver).key_down(Keys.CONTROL,body).send_keys('t').key_up(Keys.CONTROL).perform()

推荐答案

猜猜这会有所帮助:

from selenium import webdriver
driver = webdriver.Chrome()
driver.execute_script("window.open('','_blank');")

这段代码应启动新的Chrome浏览器会话,并在新标签页中打开空白页

This piece of code should start new Chrome browser session and open blank page in new tab

使用driver.execute_script("window.open('URL');")打开具有所需URL的新标签页

Use driver.execute_script("window.open('URL');") to open new tab with required URL

这篇关于chrome浏览器中python webdriver的selenium new选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆