如何检测python webdriver selenium的意外url更改?
我正在自动执行浏览器过程,但所有人都使用相同的凭据(一次只有一个用户可以访问门户),因此每当其他人登录时,当前用户将自动退出,url更改为“” 当我的自动化脚本运行时,以及当检测到注销时,是否有任何方法可以持续检查url更改,并结束脚本如何检测python webdriver selenium的意外url更改?,python,selenium,Python,Selenium,我正在自动执行浏览器过程,但所有人都使用相同的凭据(一次只有一个用户可以访问门户),因此每当其他人登录时,当前用户将自动退出,url更改为“” 当我的自动化脚本运行时,以及当检测到注销时,是否有任何方法可以持续检查url更改,并结束脚本 我正在使用python selenium webdriver。在Java中,如果您实现它,我们可以从EventLister获得帮助 public class Test2 implements WebDriverEventListener{ @Override
我正在使用python selenium webdriver。在Java中,如果您实现它,我们可以从EventLister获得帮助
public class Test2 implements WebDriverEventListener{
@Override
public void beforeFindBy(By arg0, WebElement arg1, WebDriver driver) {
if(driver.getCurrentUrl().equals("http://172.17.3.248:8889/ameyoreports/?acpMode=false#loggedOut")==true) {
//do want you want.
}
}
在执行任何操作之前,我们必须使用与下面相同的方法交叉检查url(根据上面的示例,在查找元素之前交叉检查url)
在Java中,它有助于python嘿,有一个与selenium webdriver对象关联的current\u url属性,您将能够使用webdriver.current\u url获取更改的url 保持一个检查,你可以随时打破你的脚本 您可以使用以下代码对其进行测试
#using chrome webdriver
from selenium.webdriver.chrome.options import Options
browser = Options()
instance = webdriver.Chrome(webdriver_path, options=browser)
instance.get(url)
instance.current_url <<<<<<< this will give the current url opened in browser
# manually enter another url in the browser then again check
instance.current_url
#使用chrome webdriver
从selenium.webdriver.chrome.options导入选项
浏览器=选项()
实例=webdriver.Chrome(webdriver\u路径,选项=浏览器)
获取(url)
instance.current\u url
#using chrome webdriver
from selenium.webdriver.chrome.options import Options
browser = Options()
instance = webdriver.Chrome(webdriver_path, options=browser)
instance.get(url)
instance.current_url <<<<<<< this will give the current url opened in browser
# manually enter another url in the browser then again check
instance.current_url