2017-01-20 13 views
1

私は、Webページのボタンに対処するための作業ロケータを探しています。セレンのロケータxpathが特定のボタンで機能しない

<input tabindex="-1" value="Select &amp; Upload File" class="ruButton ruBrowse" style="border: 0px dotted;" type="button"> 

私はXPathのロケータとして以下しようとしたが、これらはOKではありません - 私がしたい:私は持っている

<input class="ruButton ruBrowse" tabindex="-1" value="Select & Upload File" style="border: 0px dotted;" type="button"> 

コピーouterhtml:

コード内で "要素の検査" なるほどこのロケータはOKです

//input[@value='Select & Upload File'] 
//input[@value='Select &amp; Upload File'] 

理由を理解しますエラーログにの
driver.findElement(By.xpath("//input[contains(@class,'ruButton ruBrowse') and contains(@type,'button')]")).click(); 

詳細: 1)

driver.get(baseUrl); 
driver.findElement(By.xpath("//input[contains(@value,'Select') and contains (@value,'Upload File')]")).click(); 

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with xpath == //input[contains(@value,'Select') and contains(@value,'Upload File')] (WARNING: The server did not provide any stacktrace information) 
Command duration or timeout: 297 milliseconds 
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html 
Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700' 
System info: host: 'BGC-W7X64T-2082', ip: '10.119.137.75', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_112' 
Driver info: org.openqa.selenium.ie.InternetExplorerDriver 
Capabilities [{browserAttachTimeout=0, ie.enableFullPageScreenshot=true, enablePersistentHover=true, ie.forceCreateProcessApi=false, ie.forceShellWindowsApi=false, pageLoadStrategy=normal, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:2351/, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss}] 
Session ID: 4613c6bf-239c-4ccb-b3b3-f1946276e7c7 
*** Element info: {Using=xpath, value=//input[contains(@value,'Select') and contains(@value,'Upload File')]} 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 
at java.lang.reflect.Constructor.newInstance(Unknown Source) 
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216) 
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168) 
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635) 
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:368) 
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:473) 
at org.openqa.selenium.By$ByXPath.findElement(By.java:361) 
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:360) 
at Selenium_And_AutoIt.main(Selenium_And_AutoIt.java:61) 

2)

driver.get(baseUrl); 
driver.findElement(By.xpath("//input[@value='Select & Upload File']")).click(); 

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with xpath == //input[@value='Select & Upload File'] (WARNING: The server did not provide any stacktrace information) 
Command duration or timeout: 281 milliseconds 
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html 
Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700' 
System info: host: 'BGC-W7X64T-2082', ip: '10.119.137.75', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_112' 
Driver info: org.openqa.selenium.ie.InternetExplorerDriver 
Capabilities [{browserAttachTimeout=0, ie.enableFullPageScreenshot=true, enablePersistentHover=true, ie.forceCreateProcessApi=false, ie.forceShellWindowsApi=false, pageLoadStrategy=normal, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:21427/, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss}] 
Session ID: eb3f9de0-2fc1-41ce-8f15-6947f956c216 
*** Element info: {Using=xpath, value=//input[@value='Select & Upload File']} 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 
at java.lang.reflect.Constructor.newInstance(Unknown Source) 
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216) 
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168) 
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635) 
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:368) 
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:473) 
at org.openqa.selenium.By$ByXPath.findElement(By.java:361) 
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:360) 
at Selenium_And_AutoIt.main(Selenium_And_AutoIt.java:60) 

ありがとうございました!

+0

なぜ「これはOK」ではないと思いますか?例外ログを表示 – Andersson

+0

こんにちはAndersson、ありがとう。スレッド "main"の例外org.openqa.selenium.NoSuchElementException:xpath == // input [@ value = 'ファイルの選択とアップロード]で要素を見つけることができません(警告:サーバーはスタックトレース情報を提供しませんでした)ここでエスケープする必要がある特殊文字? –

+0

xpathロケータが正しいです。あなたはページのhtmlソースコードを投稿できますか? – ManishChristian

答えて

0

これは価値があるため、アンパサンドも内部にあるテキストを使用することで過去に問題が発生しました。私の解決策は、 "="の代わりにcontainsを使用して、値のテキストの一部のみを提供することですが、例えば "Upload File"を含む他の要素が考えられるので十分ではありません。

//input[contains(@value,'Select') and contains(@value,'Upload File')] 

、それはまた、「-で始まる」で「含む」と「終了-で」相応置き換えることができ:-あるとして、ロケータが間違っていると仮定し、この場合、私の解決策は、以下のロケータだろう。

+0

こんにちはビル・ヒルマン、私とあなたの提案を考えてくれてありがとう!私はすでにこれを試してみましたが、不幸にも運がありません。私にとって奇妙なことは:別の言語( '&'プレゼントなし)では、ロケータはうまく動作します。 –

関連する問題