多年來我一直在使用RC。我決定切換到遠程Webdriver以獲得所有這些新的好處。 首先,我想嘗試一個基本場景。打開Google.com 2.在搜索框中輸入「Selenium」。Windows 7本地主機上的Selenium遠程Webdriver拋出空指針異常
我開始獨立服務器使用以下命令
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-32bit。 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 [email protected]
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 [email protected]
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
[email protected] 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
您確定定位符「gbqfb」是用於文本輸入而不是其他任何元素嗎? – 2013-04-04 09:41:10
我相信定位器是正確的,因爲如果我故意提供一個不正確的定位器,我得到NoSuchelementException:無法找到元素 – 2013-04-04 10:21:59
看到這一行:'11:25:56.537信息 - 執行:[發送鍵:null null,[s ,e,l,e,n,i,u,m]]' - 看起來前兩個鍵是空的......但我不知道如何修復它... – 2013-04-04 10:29:39