在下载大量json数据后,Selenium驱动程序在ajax调用后一页 [英] Selenium Driver is one page behind ajax call after large json data download

查看:106
本文介绍了在下载大量json数据后,Selenium驱动程序在ajax调用后一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的代码

driver.find_element_by_xpath("//div[@aria-rowindex=7][@aria-colindex=10]//child::span[1]").click() #click will take me to a new ajax page - no change in url
driver.implicitly_wait(60)
time.sleep(160) #without this the below a.png is still behind before my previous click
driver.save_screenshot('a.png') #new url page is in screenshot properly. 
#working fine until this line
driver.implicitly_wait(60)
print(driver.page_source) #still in old page's page_source and the below xpath is not available here
WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, "//button[@button_id='fuseBlowView']"))).click()

即使屏幕截图显示了新页面,为什么驱动程序仍然保留我的旧页面?现在它像这样出错了:

Why is the driver still with my old page even if screenshot is showing new page? Now it is erroring out like this:

    WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, "//button[@button_id='fuseBlowView']"))).click()
  File "C:\Users\jrex\PycharmProjects\Dragon\venv\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:

它无法找到xpath,因为旧页面URL仍在driver.page_source中. 在打开硒的Web浏览器中,我什至可以在等待时间内单击按钮-我只是尝试过-我做了截图以证明这一点.但是为什么我的司机落后呢?

It is not able to find the xpath, because the old page url is still in driver.page_source In web browser which selenium opens, I am even able to click button during the wait time - I simply tried - I did a screenshot just to prove that. But why is my driver lagging behind?

第一次点击a.png后会有大量数据输入 这就是为什么要等待时间.只是为了引入所有数据. 我正在使用Google Chrome浏览器驱动程序.

There is a lot of data comes in after the 1st click to the a.png That is why wait time. Just to bring all the data in. I am using Google Chrome Driver.

推荐答案

尝试通过以下方法获取网页中iframe的数量: iframes = driver.find_elements_by_tag_name("iframe"),然后切换到相应的iframe并找到所需的元素,然后单击.可能有帮助!

Try getting the number of iframes in your webpage by iframes = driver.find_elements_by_tag_name("iframe") and then switch to a corresponding iframe and find that desired element and click. It might help!

这篇关于在下载大量json数据后,Selenium驱动程序在ajax调用后一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆