简体   繁体   English

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

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

I am trying to redirect or navigate to another page in the current window in the same tab but it's not working.我正在尝试重定向或导航到同一选项卡中当前 window 中的另一个页面,但它不起作用。
Thanks in Advance.提前致谢。

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

Please, make sure you define the "caps"s variable in "desired_capabilities=caps", and if you do not close the driver after using it using the close() method, it still running in memory and causes some conflicts when you try to run the script again.请确保您在“desired_capabilities=caps”中定义了“caps”变量,如果您在使用 close() 方法后没有关闭驱动程序,它仍然在 memory 中运行,并且在您尝试时会导致一些冲突再次运行脚本。

Below you can see your script with some changes:您可以在下面看到您的脚本进行了一些更改:

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