简体   繁体   English

Windows7 localhost上的Selenium Remote Webdriver引发空指针异常

[英]Selenium Remote Webdriver on Windows7 localhost throws null pointer exception

I have been using RC successfully over the years.I have decided to switch over to Remote Webdriver to get all those new benefits. 多年来,我一直在成功使用RC。我决定切换到Remote Webdriver以获取所有这些新好处。 First I wanted to try a basic scenario. 首先,我想尝试一个基本方案。 1. Open Google.com 2. Type "Selenium" in the search box. 1.打开Goog​​le.com。2.在搜索框中输入“硒”。

I start Standalone server with the following command 我使用以下命令启动独立服务器

java -jar selenium-server-standalone-2.31.0.jar -port 4450

Then I execute my python test script which contains the lines below. 然后,我执行我的python测试脚本,其中包含以下几行。

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
import time
caps = webdriver.DesiredCapabilities.FIREFOX
driver = webdriver.Remote(desired_capabilities=caps,command_executor='http://localhost:4450/wd/hub')
driver.get("http://www.google.com")
time.sleep(5)
driver.find_element_by_id("gbqfb").send_keys("selenium")
driver.quit()

I can see that google.com opens but "selenium" is not typed in the search box. 我可以看到google.com打开了,但是搜索框中没有键入“ selenium”。 In the standalone server logs I get the exception below. 在独立服务器日志中,我得到以下异常。

Configuration : Windows 7 Professional-32bit. 配置:Windows 7 Professional-32bit。 Selenium-server-standalone-2.31 Python 2.7.3 Firefox 17. Selenium-server-standalone-2.31 Python 2.7.3 Firefox 17。

I am wondering What I am missing here? 我想知道我在这里想念什么? Any help will be appreciated. 任何帮助将不胜感激。 Thanks! 谢谢!

C:\Users\engin\Downloads>java -jar selenium-server-standalone-2.31.0.jar -port 4
450
Nis 04, 2013 11:24:35 AM org.openqa.grid.selenium.GridLauncher main
INFO: Launching a standalone server
11:24:36.180 INFO - Java: Oracle Corporation 23.7-b01
11:24:36.180 INFO - OS: Windows 7 6.1 x86
11:24:36.195 INFO - v2.31.0, with Core v2.31.0. Built from revision 1bd294d
11:24:36.351 INFO - RemoteWebDriver instances should connect to: http://127.0.0.
1:4450/wd/hub
11:24:36.367 INFO - Version Jetty/5.1.x
11:24:36.367 INFO - Started HttpContext[/selenium-server/driver,/selenium-server
/driver]
11:24:36.367 INFO - Started HttpContext[/selenium-server,/selenium-server]
11:24:36.367 INFO - Started HttpContext[/,/]
11:24:36.398 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@b1656f

11:24:36.398 INFO - Started HttpContext[/wd,/wd]
11:24:36.398 INFO - Started SocketListener on 0.0.0.0:4450
11:24:36.398 INFO - Started org.openqa.jetty.jetty.Server@18facfb
11:25:42.012 INFO - Executing: [new session: {platform=ANY, javascriptEnabled=tr
ue, browserName=firefox, version=}] at URL: /session)
11:25:48.987 INFO - Done: /session
11:25:49.003 INFO - Executing: org.openqa.selenium.remote.server.handler.GetSess
ionCapabilities@19e774d at URL: /session/3ff2660f-0a08-420d-b3df-eb5b699e4a6b)
11:25:49.003 INFO - Done: /session/3ff2660f-0a08-420d-b3df-eb5b699e4a6b
11:25:49.018 INFO - Executing: [get: http://www.google.com] at URL: /session/3ff
2660f-0a08-420d-b3df-eb5b699e4a6b/url)
11:25:51.436 INFO - Done: /session/3ff2660f-0a08-420d-b3df-eb5b699e4a6b/url
11:25:56.444 INFO - Executing: [find element: By.id: gbqfb] at URL: /session/3ff
2660f-0a08-420d-b3df-eb5b699e4a6b/element)
11:25:56.537 INFO - Done: /session/3ff2660f-0a08-420d-b3df-eb5b699e4a6b/element
11:25:56.537 INFO - Executing: [send keys: null null, [s, e, l, e, n, i, u, m]]
at URL: /session/3ff2660f-0a08-420d-b3df-eb5b699e4a6b/element/0/value)
11:25:56.537 WARN - Exception thrown
java.lang.NullPointerException
        at org.openqa.selenium.remote.server.handler.SendKeys.call(SendKeys.java
:49)
        at org.openqa.selenium.remote.server.handler.SendKeys.call(SendKeys.java
:1)
        at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession
.java:169)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
    11:25:56.553 WARN - Exception: null

One solution we have found was... Adding -Duser.language=en to the java arguments while starting the server solved the issue!! 我们发现的一种解决方案是...在启动服务器时将-Duser.language = en添加到java参数中解决了该问题! and by the way my OS language is Turkish(TR). 顺便说一下,我的操作系统语言是土耳其语(TR)。

I had a really similar issue before and I found this: 之前我有一个非常类似的问题,发现了这一点:

https://github.com/mozilla/geckodriver/issues/659 https://github.com/mozilla/geckodriver/issues/659

It seems like the method send_keys is broken. 似乎send_keys方法已损坏。 They should have fixed it already so you could pull the newest version and build it yourself or you can use an older version where the send_keys method works. 他们应该已经对其进行了修复,因此您可以拉动最新版本并send_keys构建,也可以使用send_keys方法起作用的较旧版本。

That worked for me. 那对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM