【发布时间】:2013-11-26 07:02:12
【问题描述】:
我正在尝试登录一个有很多 ajax 的网站。我的连接速度很慢,所以需要一些时间,但我可以在所有内容加载之前看到登录表单并登录。登录表单未加载 ajax。
driver = webdriver.Firefox()
driver.get("http://www.example.com")
print 'returned'
print 'finding element'
password_element = driver.find_element(By.NAME,'password')
print 'sending password'
password_element.send_keys('pass')
输出是:
>>returned
>>finding element
(waiting for 5 minutes)
>>sending password
它返回的速度非常快,并且“返回”被打印出来。但是它卡在“查找元素”中,并且必须在返回元素之前加载所有 ajax。在我的 Firefox 窗口中,WebDriver 以红色写在底部栏中,然后在加载所有内容时变为黑色。
我的 selenium 版本是 2.37.2,firefox 版本是 25.0.1。我在之前的帖子中看到我应该更改版本,但这些不适用于这些。
【问题讨论】:
-
对不起,我不明白你的问题是关于什么的。你已经解释了情况,你希望它更快吗?不等待所有的 AJAX 再继续或其他什么?
-
@Mark Rowlands 没错,我不想等待所有的ajax加载到主页上,我想直接登录。
-
好的,我会尝试的第一件事是使用
WebdriverWait显式等待password_element。所以像wait = WebdriverWait(driver, 10) wait.until(ExpectedConditions.presence_of_element_located((By.NAME, "password"))) driver.find_element(By.NAME, "password").send_keys("pass")这样的东西我不能 100% 确定使用显式等待是否会“破坏”页面加载时间,但我猜它值得一试。 -
我试过了,然后程序先等待10秒,然后卡在wait.until(ExpectedConditions.presence_of_element_located - 函数。实际上如果找到它会返回一个web元素。似乎其他人也有同样的情况问题,stackoverflow.com/questions/13711799/… 和 stackoverflow.com/questions/17919503/…,但使用的是旧版本。烦人的是表单总是出现在浏览器中,所以我可以随时登录。
-
那么肯定是个问题。抱歉,我帮不上忙。