繁体   English   中英

我如何使用 Selenium Python 重定向(导航)到新的 url

[英]How do i redirect (navigate) to new url with Selenium Python

我正在尝试重定向或导航到同一选项卡中当前 window 中的另一个页面,但它不起作用。
提前致谢。

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() 方法后没有关闭驱动程序,它仍然在 memory 中运行,并且在您尝试时会导致一些冲突再次运行脚本。

您可以在下面看到您的脚本进行了一些更改:

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()

暂无
暂无

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

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