python - 我如何使用 Selenium Python 重定向(导航)到新的 url
问题描述
我正在尝试重定向或导航到同一选项卡中当前窗口中的另一个页面,但它不起作用。
提前致谢。
url = 'https://www.nintendo.com/'
new_url = 'https://www.rockstargames.com/'
driver = webdriver.Chrome(desired_capabilities=caps, executable_path=r'/usr/local/bin/chromedriver')
driver.get(url)
# Do some stuff
getMeGames()
# This is not working
driver.get(new_url)
# Do more Stuff
getMeVideos()
解决方案
请确保您在“desired_capabilities=caps”中定义了“caps”变量,如果您在使用 close() 方法后没有关闭驱动程序,它仍然在内存中运行并在您尝试时会导致一些冲突再次运行脚本。
您可以在下面看到您的脚本进行了一些更改:
from selenium.webdriver import Chrome
from time import sleep
driver = Chrome(executable_path=r'/usr/local/bin/chromedriver')
url = 'https://www.nintendo.com/'
new_url = 'https://www.rockstargames.com/'
driver.get(url)
# Do some stuff
def getMeGames():
pass # do nothing
# This is not working
driver.get(new_url)
# Do more Stuff
def getMeVideos():
pass # do nothing
# waits for 3 seconds
sleep(3)
# close the current page
driver.close()
推荐阅读
- wso2 - 使用 Docker Testcontainers 测试 WSO2 REST API
- android - 授予应用管理员权限可防止其终止辅助功能服务
- javascript - 如何从 fetch Response 对象中提取 [Symbol(Response internals)]?
- java - 未找到本机 micronaut 数据插入查询的可能实现
- javascript - 有没有办法纯粹通过代码 Javascript 创建 Quicksight 分析?
- uml - 序列图改变状态
- class - 关于嵌套结构和实例检查的疑问
- google-sheets - 如何有条件地在 google-sheet 中添加一个可点击的复选框?
- python - Selenium 和 Python 的动态元素
- javascript - 为什么我的切换不显示?以及如何切换到侧面?