Dimencion Rider
Dimencion Rider

Reputation: 175

WebDriver, Python: How to catch dynamically updating url with the appropriate value and save it to the variable

python/selenium web driver code:

elem = driver.find_element_by_css_selector("#username")
elem.send_keys("username")
elem = driver.find_element_by_css_selector("#password")
elem.send_keys("password")

driver.implicitly_wait(2) #seconds
elem = driver.find_element_by_css_selector("button")
elem.click()

def condition(driver):
    look_for = ("url_which_contains_this_text")
    url = driver.current_url
    for look_for in url:
        if url.find(look_for) != -1:
            print url

    return url

#page_url = driver.current_url
print url

In this code: 1) user login; 2) click 'login button'; And then I need to catch somehow the URL which is dynamically changing every second (access token loaded, etc), and catch the URL which contains value "example_id=" and save this url to variable and print.

Сan someone help me ?

Upvotes: 2

Views: 983

Answers (1)

Andersson
Andersson

Reputation: 52685

I'm not sure that this will work as I cannot test it, but you may try something like this:

required_url = ""
while True:
    current_url = driver.current_url
    if "example_id=" in current_url:
        required_url = current_url
        print('\n'+required_url)
        break
    else: print(current_url)

Upvotes: 2

Related Questions