如何使硒在从实际网站获取内容之前等待,该内容通过IEDriverServer和IE登陆页面后加载 [英] How to make selenium wait before getting contents from the actual website which loads after the landing page through IEDriverServer and IE

查看:61
本文介绍了如何使硒在从实际网站获取内容之前等待,该内容通过IEDriverServer和IE登陆页面后加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

driver = webdriver.Ie("C:\\IEDriverServer.exe")
driver.get(testurl)
driver.refresh()
time.sleep(5)
data = driver.find_element_by_id("__content0-value-scr")

因此,我试图使用Selenium(Python)和Internet Explorer通过其ID查找元素,因为由于公司法规的限制,我仅限于Internet Explorer.

So I'm trying to find an element by it's id using Selenium (Python) and Internet Explorer, because I'm limited to Internet Explorer due to company regulations.

我的问题如下:在 driver.get(testurl)上,selenium加载页面,但IE首先以IEDriver登陆页面启动.只有在此之后,它才会加载请求的网址.

My problem is as follows: on driver.get(testurl), selenium loads the page but IE first starts up with the IEDriver landing page. Only after that, it loads the requested url.

这里的问题是Selenium将IE驱动程序登录页面识别为要加载的url,因此忽略了我要搜索的页面,此后该页面就被加载了.

The problem here is that Selenium recognizes the IE Driver landing page as the url to be loaded and therefore ignores the page I want to search on, which gets loaded after that.

有人知道如何解决此问题吗?

Has anyone got an idea on how to work around this?

推荐答案

当您使用 Selenium IEDriverServer Internet Explorer 时,而 IEDriverServer 启动一个新的 IE浏览器会话, IE浏览器首先使用 IEDriver登录页面启动,然后加载请求的网址.

When you use Selenium, IEDriverServer and Internet Explorer, while IEDriverServer initiates a new IE Browser session, IE Browser first starts up with the IEDriver landing page and then loads the requested url.

如果 Selenium IEDriverServer 的登录页面识别为要加载的网址,在这种情况下,解决方案将是诱使 WebDriverWait 页面标题等同于 AUT(被测应用程序)的实际页面标题.

Incase Selenium recognizes the IEDriverServer's landing page as the url to be loaded, in that case the solution would be to induce WebDriverWait for the Page Title to be equivalent to the actual page title of the AUT (Application Under Test).

  • 代码块:

  • Code Block:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

testurl = "https://www.facebook.com/" # replace with the url of the AUT
driver = webdriver.Ie(executable_path=r'C:\path\to\IEDriverServer.exe')
driver.get(testurl)
WebDriverWait(driver, 10).until(EC.title_contains("Facebook")) # # replace with the title of the AUT
data = driver.find_element_by_id("__content0-value-scr")

这篇关于如何使硒在从实际网站获取内容之前等待,该内容通过IEDriverServer和IE登陆页面后加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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