セレン テストを Firefox ブラウザーから HTMLUnit ドライバーに変換しようとしています。しかし、HTMLUnit テストを実行しようとすると、XPATH でエラーが発生します。Firefox ブラウザ テストはまったく問題なく実行されます。
私のアプリケーション テスト スイートは XPATH を広く使用しています。したがって、私は意図的に XPATH を試しています。
私はすでに使用してみました
new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated
それでも同じエラーが発生しました。
これはエラーです:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate a node using .//*[@id='tsf']/div[2]/div[3]/center/input[1]
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:55:52'
System info: host: 'WL309476', ip: '10.83.16.25', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_66'
Driver info: driver.version: HtmlUnitDriver
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByXPath(HtmlUnitDriver.java:1161)
at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1715)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.implicitlyWaitFor(HtmlUnitDriver.java:1363)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:1711)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:606)
at seleniumtest.Test_Google.main(Test_Google.java:17)
これは私のFirefoxブラウザテストです:
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.co.in/");
WebElement e =driver.findElement(By.xpath(".//*[@id='tsf']/div[2]/div[3]/center/input[1]"));
System.out.println("The current element is " + e.getAttribute("value"));
これは私の HtmlUnit テストです:
WebDriver driver = new HtmlUnitDriver(true);
driver.get("https://www.google.co.in/");
WebElement e =driver.findElement(By.xpath(".//*[@id='tsf']/div[2]/div[3]/center/input[1]"));
System.out.println("The current element is " + e.getAttribute("value"));
私の場合はJavaScriptが関係していないので、重複しているとは思いません。単純なテストを Firefox ドライバーから HTMLUnit に移植したいだけです。