Python Selenium PhantomJS - 禁用Javascript后,我无法单击任何内容或获取任何元素



我需要帮助。在PhantomJS网络驱动程序上禁用Javascript后,我无法使用browser.find_element_by_id或任何类似方法获取或单击任何元素。

以下是我设置幻影的方式:

def phantom_settings_function():
# PhantomJS settings
phantom_settings = dict(DesiredCapabilities.PHANTOMJS)
phantom_settings['phantomjs.page.settings.userAgent'] = ('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36')
phantom_settings['phantomjs.page.settings.javascriptEnabled'] = False,   
phantom_settings['phantomjs.page.settings.loadImages'] = False,
phantom_settings['phantomjs.page.browserName'] = 'Google Chrome'
return phantom_settings
browser = webdriver.PhantomJS(desired_capabilities=phantom_settings_function(), service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'])

这是我尝试单击元素的方式:

browser.find_element_by_id('c_btnPriceRange').click()

我收到此错误:

selenium.common.exceptions.NoSuchElementException: Message: {"request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"96","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:52780","User-Agent":"Python-urllib/3.5"},"httpVersion":"1.1","method":"POST","post":"{\"value\": \"c_btnPriceRange", "using": \"id", \"sessionId": \"871daac0-147f-11e7-bfdf-4dce0d86731e\"}","url":"/element","urlParsed":{"anchor":","query":","file":"element","directory":"/","path":"/element","relative":"/element","port",","host":","password":","user":","userInfo":","authority":","protocol":","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/871daac0-147f-11e7-bfdf-4dce0d86731e/element"}} 屏幕截图:可通过屏幕访问

我已经尝试显式等待元素,但它不起作用,当我打印网页的内容时,我得到了包含元素的完整 HTML 代码。 禁用JavaScript是否使Selenium无法运行命令或其他东西?

我真的需要这方面的帮助。

谢谢

我在PhantomJS Web驱动程序中也遇到了NoSuchElementException问题。 我的修复,基于

Python/Selenium/PhantomJS - 执行之间保留的数据

是要添加

browser.implicitly_wait(10)
browser.set_window_size(1120, 550)

以前

browser.find_element_by_id

最新更新