我使用 selenium-java-2.32.0
我之前使用过 selenium,但我从未使用过 HtmlUnitDriver。
有一个 html 页面,让它成为 localhost/mainPage
我创建了新的 HtmlUnitDriver:
WebDriver driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_17);
driver.setJavascriptEnabled(true);
然后我导航到我的页面:
driver.get(page);
其中页面是“localhost/mainPage”。在这个页面上有一个按钮。当我尝试单击它时:
driver..findElement(By.id("button_ok")).click();
我得到以下异常:
org.openqa.selenium.ElementNotVisibleException: You may only interact with visible elements
Build info: version: '2.32.0', revision: '6c40c18', time: '2013-04-09 17:23:22'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_43'
Driver info: driver.version: unknown
at org.openqa.selenium.htmlunit.HtmlUnitWebElement.verifyCanInteractWithElement(HtmlUnitWebElement.java:290)
at org.openqa.selenium.htmlunit.HtmlUnitWebElement.click(HtmlUnitWebElement.java:140)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:41)
at com.sun.proxy.$Proxy17.click(Unknown Source)
at com.epam.sbrf.pages.Page.click(Page.java:85)
at com.epam.sbrf.utils.TestMethodStatusPay.searchBrakByLinumAndFinishTransfer(TestMethodStatusPay.java:87)
at com.epam.sbrf.pages.PaySearchPage.searchBrakByLinumAndTransferFinished(PaySearchPage.java:678)
at com.epam.sbrf.test.CheckAscertainStatusPay.sendFromControlToAscertain(CheckAscertainStatusPay.java:67)
at com.epam.sbrf.test.CheckAscertainStatusPay.checkStatusFromAscertainToReturnedToPayer(CheckAscertainStatusPay.java:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
我试图调试它,我发现:
1. driver.getCurrentPage() - “localhost/mainPage”。这是正确的。
2. drivet.getPageSource() - 不包含“button_ok”。
因此,我将页面和驱动程序导航到此页面。此页面上有一个按钮。但是在页面的源代码中没有按钮 - 也许有问题?页面由很多部分构成,它是jsp。我实际上不明白它是如何工作的——这个项目又旧又大,而且我与它以前的开发人员没有联系。
问题是 - HtmlUnitDriver 如何呈现页面?如果页面的源代码不包含任何元素 - HtmlUnitDriver 将无法与之交互?