Selenium Driver 在 json 大数据下载后调用落后 ajax 一页
Selenium Driver is one page behind ajax call after large json data download
我有这样的代码
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()
为什么即使屏幕截图显示的是新页面,driver 仍然在我的旧页面上?现在它是这样出错的:
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
在 selenium 打开的网络浏览器中,我什至可以在等待时间内单击按钮 - 我只是尝试过 - 我做了一个截图来证明这一点。但是为什么我的driver落后了?
第一次点击后有大量数据进来a.png
这就是等待时间的原因。只是为了把所有的数据都带进来。
我正在使用 Google Chrome Driver.
尝试通过以下方式获取网页中 iframe 的数量
iframe = driver.find_elements_by_tag_name("iframe") 然后切换到相应的 iframe 并找到所需的元素并单击。可能会有帮助!
我有这样的代码
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()
为什么即使屏幕截图显示的是新页面,driver 仍然在我的旧页面上?现在它是这样出错的:
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 在 selenium 打开的网络浏览器中,我什至可以在等待时间内单击按钮 - 我只是尝试过 - 我做了一个截图来证明这一点。但是为什么我的driver落后了?
第一次点击后有大量数据进来a.png 这就是等待时间的原因。只是为了把所有的数据都带进来。 我正在使用 Google Chrome Driver.
尝试通过以下方式获取网页中 iframe 的数量 iframe = driver.find_elements_by_tag_name("iframe") 然后切换到相应的 iframe 并找到所需的元素并单击。可能会有帮助!