Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python的WebDriver:如何捕获具有适当值的动态更新url并将其保存到变量_Python_Selenium_Selenium Webdriver_Webdriver_Robotframework - Fatal编程技术网

Python的WebDriver:如何捕获具有适当值的动态更新url并将其保存到变量

Python的WebDriver:如何捕获具有适当值的动态更新url并将其保存到变量,python,selenium,selenium-webdriver,webdriver,robotframework,Python,Selenium,Selenium Webdriver,Webdriver,Robotframework,python/selenium web驱动程序代码: 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_el

python/selenium web驱动程序代码:

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
在此代码中: 1) 用户登录; 2) 点击“登录按钮”; 然后我需要捕捉动态变化的URL 每秒(访问加载的令牌等),并捕获 包含值“example_id=”并将此url保存到变量并打印


С有人帮我吗?

我不确定这是否有效,因为我无法测试它,但您可以尝试以下方法:

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)

是否要定义成功授权后打开的实际网页url?单击“登录”按钮后,在加载仪表板页面之前会返回两个url。我需要捕捉其中的一个,它将包含“example\u id=“value.不错的解决方案,但是……问题是,目标url是动态生成的动态url。我没有这个URL的静态值,所以当我使用这部分代码(first if)时,只保留first
if
operator:)好的。它什么也不返回。我什么也不能打印。“nameError:name'current_url'未定义”它仍然需要一些小的修复,但可以工作!非常感谢:)