1

私の Web アプリケーションには、Gmail の受信トレイと同じように受信トレイがあります。私の目的は、メール アイテムをクリックしてその内容を確認することです。

受信トレイのメール アイテムの外側の HTML は次のとおりです。

<a href="read_body.php?mailbox=INBOX&amp;passed_id=2&amp;startMessage=1">Complete Registration Request- My WebSite</a>

私は次のようにJavaコードを書きました

driver.findElement(By.partialLinkText("Complete Registration Request- My WebSite")).click();

(ps:linkTextでも試しました)。

別のアプローチは

  @FindBy(how=How.LINK_TEXT,using="link=Complete Registration Request- My WebSite")
  @CacheLookup
  private WebElement regMailLink;

内部メソッド

 regMailLink.click();

どちらの場合も、出力は次のようになりました。

org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"partial link text","selector":"Complete Registration Request- My WebSite"}
Command duration or timeout: 31.44 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.28.0', revision: '18309', time: '2012-12-11 20:21:18'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_39'
Session ID: 2baf4e73-c070-4046-8723-b4ae430a827d
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=firefox, rotatable=false, locationContextEnabled=true, version=16.0, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, browserConnectionEnabled=true, nativeEvents=true, webStorageEnabled=true, applicationCacheEnabled=true, takesScreenshot=true}]
    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:187)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:533)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:302)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByPartialLinkText(RemoteWebDriver.java:347)
    at org.openqa.selenium.By$ByPartialLinkText.findElement(By.java:265)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:294)
    at stabilix.org.hc.MailCode.testValidateEmail(MailCode.java:74)
    at stabilix.org.hc.createUserPageTest.NewUsrStage1(createUserPageTest.java:48)
    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:80)
    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:128)
    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:1203)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1128)
    at org.testng.TestNG.run(TestNG.java:1036)
    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)
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Unable to locate element: {"method":"partial link text","selector":"Complete Registration Request- My WebSite"}
Build info: version: '2.28.0', revision: '18309', time: '2012-12-11 20:21:18'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_39'
Driver info: driver.version: unknown
    at <anonymous class>.<anonymous method>(file:///C:/DOCUME~1/moshe/LOCALS~1/Temp/anonymous7889540798209195994webdriver-profile/extensions/fxdriver@googlecode.com/components/driver_component.js:8251)
    at <anonymous class>.<anonymous method>(file:///C:/DOCUME~1/moshe/LOCALS~1/Temp/anonymous7889540798209195994webdriver-profile/extensions/fxdriver@googlecode.com/components/driver_component.js:382)
---
---
4

2 に答える 2

2

まぁ、いいよ。これはまだアドバイスというよりも考えです:

あなたのコメントによると、そのアプリケーションにはフレームがあります。そして、このリンクはフレーム内になると思います。そして、このフレームには次の名前が必要です。

 <frame name="main"> //my guess
   //...
   <a href="read_body.php?mailbox=INBOX&amp;passed_id=2&amp;startMessage=1">Complete Registration Request- My WebSite</a>
   //...
 </frame>

したがって、ドライバーをこのフレームに切り替えるために最初に行う必要があるのは、

driver.switchTo.frame("main");

そして、検索を実行できます

driver.findElement(By.partialLinkText("Complete Registration Request- My WebSite")).click();

フレーム名は私自身の推測であるため、私のコードをコピーペーストしないでください。ガイドとして使用してください;)

于 2013-02-26T10:21:35.850 に答える
0

ここで実際には、以下の CSS セレクターで試すことができます

css=a[href*='INBOX']

この CSS を使用して、スクリプトが機能しているかどうかをお知らせください。

于 2014-04-08T07:04:16.923 に答える