Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.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
Python Windows7 localhost上的Selenium远程Webdriver引发空指针异常_Python_Windows_Selenium_Remotewebdriver - Fatal编程技术网

Python Windows7 localhost上的Selenium远程Webdriver引发空指针异常

Python Windows7 localhost上的Selenium远程Webdriver引发空指针异常,python,windows,selenium,remotewebdriver,Python,Windows,Selenium,Remotewebdriver,多年来,我一直在成功地使用RC。我决定改用远程Webdriver来获得所有这些新的好处。 首先,我想尝试一个基本场景。 1.打开Google.com 2.在搜索框中键入“Selenium” 我使用以下命令启动独立服务器 java -jar selenium-server-standalone-2.31.0.jar -port 4450 然后我执行python测试脚本,其中包含以下几行代码 from selenium import webdriver from selenium.common.e

多年来,我一直在成功地使用RC。我决定改用远程Webdriver来获得所有这些新的好处。 首先,我想尝试一个基本场景。 1.打开Google.com 2.在搜索框中键入“Selenium”

我使用以下命令启动独立服务器

java -jar selenium-server-standalone-2.31.0.jar -port 4450
然后我执行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()
我可以看到google.com打开了,但搜索框中没有输入“selenium”。在独立服务器日志中,我得到以下异常

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

我想知道我在这里错过了什么?任何帮助都将不胜感激。谢谢

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

我们找到的一个解决方案是。。。 在启动服务器时向java参数添加-Duser.language=en解决了这个问题!!
顺便说一下,我的操作系统语言是土耳其语(TR)。

我以前也有过类似的问题,我发现:

似乎方法
send\u keys
已损坏。他们应该已经修复了它,这样你就可以自己拉最新的版本并构建它,或者你可以在
send\u keys
方法起作用的地方使用较旧的版本


这对我很有用。

你确定定位器“gbqfb”是用于文本输入而不是任何其他元素吗?我确信定位器是正确的,因为如果我故意提供错误的定位器,我不会得到任何TouchElementException:找不到元素请参见此行:
11:25:56.537 INFO-正在执行:[发送键:null,[s,e,l,e,n,i,u,m]
-前两个键似乎为null…但我不知道如何修复它…@AbhijeetVaikar元素的类型也是正确的。我只是用Selenium IDE查找功能尝试了一下。(id=gbqfq).It黄色高亮显示搜索框。使用此id,我仍然会收到空指针异常。还尝试打开www.altavista.com并在那里的搜索框(id=yschsp)中输入一些文本。没有区别。。