1

I am automating a browser process but same credentials are used by all the persons(only one user can access the portal at a time), so whenever somebody else login-in, the current user is automatically kicked out with url change to "http://172.17.3.248:8889/ameyoreports/?acpMode=false#loggedOut".

Is there any way to constantly check for url change while my automatation script is running along and when logout is detected end the script.

I am using python selenium webdriver.

2 Answers 2

1

In Java we can take help from EventLister https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/events/WebDriverEventListener.html for example if you implement it

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.
    }
}

we have to use the same like below to cross check url before doing any action (as per above example, cross check url before finding element)

    FirefoxDriver driver = new FirefoxDriver();
     EventFiringWebDriver eventDriver = new EventFiringWebDriver(driver);

    EventHandler handler = new EventHandler();
    eventDriver.register(handler);
    eventDriver.get("url");

in Java it helps http://toolsqa.com/selenium-webdriver/event-listener/ for python http://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.support.abstract_event_listener

Sign up to request clarification or add additional context in comments.

Comments

0

hey there is current_url attribute associated with the selenium webdriver object, you will be able to fetch the changed url using webdriver.current_url.

Keep a check for that and you can break your script whenever you want.

You can test it with the following code

#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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.