无法在 Firefox 中打开网页 - Selenium Python
Webpage not opening in Firefox - Selenium Python
我正在尝试使用 Selenium 远程 运行 一个网页,然后点击它触发一个按钮。我能够成功打开 Firefox,但网页未加载,一段时间后 Firefox 自动关闭。 (试过 google.com 和其他页面作为测试,也没有加载)。谁能建议在这里做什么?
OS - Ubuntu 14.04.1
Python - 2.7.6
硒 - 3.3.0
火狐 - 39.0.3
这是我的 python 代码
import urllib, urllib2, cookielib
from contextlib import closing
from selenium import webdriver
from selenium.webdriver import Firefox # pip install selenium
from selenium.webdriver.support.ui import WebDriverWait
with closing(Firefox(executable_path="/usr/bin/firefox")) as driver:
driver.implicitly_wait(10)
driver.get("https://www.google.com")
#driver.get("http://wsb.com/Assingment2/expcase16.php")
button = driver.find_element_by_id('send')
button.click()
target_window = driver.window_handles[1]
driver.switch_to_window(target_window)
exploit_page_content = driver.page_source
print "Exploit successful \n" + exploit_page_content
您似乎正在使用 conextlib.closing()
并且根据文档,您基本上是在对象上调用 close()
方法:
from contextlib import contextmanager
@contextmanager
def closing(thing):
try:
yield thing
finally:
thing.close()
并且根据 selenium 文档:
driver.close()
– It closes the the browser window on which the focus is set.
至于建议,这取决于你想做什么。如果你想继续处理网页,那么显然要扩展你的代码。或者删除上下文并在完成后显式调用 driver.close()
。同样,这取决于您的任务是什么。
我怀疑 selenium 正在尝试使用 geckodriver,因为这是默认设置。但只有 48 版的 Firefox 才支持它。 。尝试使用旧版 Firefox 驱动程序,如下所示:
driver = Firefox(executable_path="/usr/bin/firefox", capabilities= {"marionette": False })
我正在尝试使用 Selenium 远程 运行 一个网页,然后点击它触发一个按钮。我能够成功打开 Firefox,但网页未加载,一段时间后 Firefox 自动关闭。 (试过 google.com 和其他页面作为测试,也没有加载)。谁能建议在这里做什么?
OS - Ubuntu 14.04.1
Python - 2.7.6
硒 - 3.3.0
火狐 - 39.0.3
这是我的 python 代码
import urllib, urllib2, cookielib
from contextlib import closing
from selenium import webdriver
from selenium.webdriver import Firefox # pip install selenium
from selenium.webdriver.support.ui import WebDriverWait
with closing(Firefox(executable_path="/usr/bin/firefox")) as driver:
driver.implicitly_wait(10)
driver.get("https://www.google.com")
#driver.get("http://wsb.com/Assingment2/expcase16.php")
button = driver.find_element_by_id('send')
button.click()
target_window = driver.window_handles[1]
driver.switch_to_window(target_window)
exploit_page_content = driver.page_source
print "Exploit successful \n" + exploit_page_content
您似乎正在使用 conextlib.closing()
并且根据文档,您基本上是在对象上调用 close()
方法:
from contextlib import contextmanager
@contextmanager
def closing(thing):
try:
yield thing
finally:
thing.close()
并且根据 selenium 文档:
driver.close()
– It closes the the browser window on which the focus is set.
至于建议,这取决于你想做什么。如果你想继续处理网页,那么显然要扩展你的代码。或者删除上下文并在完成后显式调用 driver.close()
。同样,这取决于您的任务是什么。
我怀疑 selenium 正在尝试使用 geckodriver,因为这是默认设置。但只有 48 版的 Firefox 才支持它。
driver = Firefox(executable_path="/usr/bin/firefox", capabilities= {"marionette": False })