Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.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
selenium在使用python打开页面后无法获取该页面_Python_Selenium_Selenium Webdriver_Selenium Iedriver - Fatal编程技术网

selenium在使用python打开页面后无法获取该页面

selenium在使用python打开页面后无法获取该页面,python,selenium,selenium-webdriver,selenium-iedriver,Python,Selenium,Selenium Webdriver,Selenium Iedriver,我有以下代码: from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from selenium.webdriver.support.ui import Select from selenium.webdriver.common.by import By # import org.openqa.selenium.Keys impor

我有以下代码:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
# import org.openqa.selenium.Keys
import datetime
import time
import unittest



cap = DesiredCapabilities().INTERNETEXPLORER
cap['ignoreProtectedModeSettings'] = True
cap['IntroduceInstabilityByIgnoringProtectedModeSettings'] = True
cap['nativeEvents'] = True
cap['ignoreZoomSetting'] = True
cap['requireWindowFocus'] = True
cap['INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS'] = True
browser = webdriver.Ie(capabilities=cap, executable_path=r'C:\IEDriverServer_x64_3.150.1\IEDriverServer.exe')
browser.implicitly_wait(2)

browser.get("https://www.google.ro/?safe=active&ssui=on")


search_form = browser.find_element_by_xpath('/html[1]/body[1]/div[1]/div[1]/div[3]/div[1]/button[1]')
search_form.click()
我尝试打开的任何页面都会在一段时间后返回超时错误:

Traceback (most recent call last):
  File "C:\Users\MunteanuG\AppData\Local\Programs\Python\Python38\lib\unittest\case.py", line 60, in testPartExecutor
    yield
  File "C:\Users\MunteanuG\AppData\Local\Programs\Python\Python38\lib\unittest\case.py", line 672, in run
    self._callSetUp()
  File "C:\Users\MunteanuG\AppData\Local\Programs\Python\Python38\lib\unittest\case.py", line 630, in _callSetUp
    self.setUp()
  File "C:\Users\MunteanuG\PycharmProjects\Dex_Automation\SRC\utilityTools.py", line 24, in setUp
    self.browser.get("https://www.google.ro/?safe=active&ssui=on")
  File "C:\Users\MunteanuG\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
    self.execute(Command.GET, {'url': url})
  File "C:\Users\MunteanuG\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\MunteanuG\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: Timed out waiting for page to load.
我使用的是python 3.7解释器。
Post主要是代码,向Post添加文本,测试您试图加载的页面似乎加载了某种JavaScript或无法访问

尝试使用以下命令禁用JavaScript

from selenium.webdriver.Ie.options import Options

options = Options()
options.preferences.update({'javascript.enabled': False})
browser = webdriver.Ie(options=options,executable_path="path")
如果仍然不起作用,请尝试删除所有功能。

如果您仔细查看以下几点,请明确指出:

保护模式 在Windows Vista或Windows 7上的Internet Explorer 7或更高版本上,必须将每个区域的保护模式设置设置为相同的值。该值可以打开或关闭,只要每个分区的值相同。要设置受保护模式设置,您必须从“工具”菜单中选择“Internet选项”,然后单击“安全”选项卡。对于每个区域,选项卡底部都会有一个复选框,标记为启用保护模式

此外,@JimEvans在文章中明确提到:

不过,使用该功能并不能解决根本问题。如果跨越受保护模式边界,可能会导致非常意外的行为,包括挂起、元素位置不工作以及未传播的单击。为了提醒人们注意这一潜在问题,该功能被冠以听起来很吓人的名字,如Java中的“忽略安全域”和.NET中的“忽略受保护的节点设置”等。我们真的认为,告诉用户使用此设置会在他们的代码中引入潜在的不好因素会阻止其使用,但事实并非如此


解决方案 您可以访问url
https://www.google.ro/?safe=active&ssui=on
使用以下解决方案:

from selenium import webdriver

driver = webdriver.Ie(executable_path=r'C:\WebDrivers\IEDriverServer.exe')
driver.get('https://www.google.ro/?safe=active&ssui=on')

工具书类 您可以在以下内容中找到一些相关的详细讨论:


在browser.get之后添加显式或隐式,等待该元素可供clickHmm使用,但这会有帮助吗?因为没有任何页面被识别为已打开或已完全加载,我想这是一个潜在的问题,我不认为等待会起作用,但我;i’我将尝试检查IE是否能够手动加载同一页面i’m收到此错误
AttributeError:“Options”对象没有selenium.webdriver.IE.Options导入选项中的属性“preferences”
,“IE”未找到,而我将其替换为“IE”,这似乎还可以,但“Options”类首选项不存在,我试过chrome驱动程序,它工作得很好,所以问题是我的互联网探险家我希望我能使用chrome,我被IE卡住了,甚至没有edge。。。我必须让它工作,嗯,我知道你应该能够通过改变浏览器配置来禁用javascript,默认情况下从工具中禁用它,它的行为似乎是一样的,页面中的某些内容仍然没有加载,在我尝试加载的任何页面上