さて、完全に無名: すべての行にCSS IDが1つ増えたページがあります。そして、私はこのようなテーブルのオークションIDを検索しています。以前のセレニウムテストで入力したオークションと照合しています。 「auctionIdには、」前のテストでメソッドに送信されWebDriver getTextが例外をスローする
int i = 0;
Boolean stillHaveSomethingToSearch = true;
Boolean foundit = false;
while (stillHaveSomethingToSearch){
idConstructor = "mainForm:aucPanelId:0:listOfAuctions:"+i;
try{
auctionRow = driver.findElement(By.id(idConstructor));
} catch (NoSuchElementException e){
stillHaveSomethingToSearch = false;
}
if (stillHaveSomethingToSearch) {
foundAuctionID = auctionRow.getText();
System.out.println("foundAuctionID = " + foundAuctionID);
if (auctionID.equals(foundAuctionID)){
stillHaveSomethingToSearch = false;
foundit = true;
}
}
i++;
}
if (foundit){
auctionRow.click();
}
:だから私のコードは次のようになります。 Webelementが実際auctionIdには、私はクリック()コマンドを送信した後、それは私が開きますので、
<span id="mainForm:aucPanelId:0:listOfAuctions:0">116</span>
行全体が、クリック可能で保存されている2つのスパンで表される
auctionRowはオークション
を見つけました奇妙なもの:auctionRow.getText();がエラーをスローします。私はそれが正しくどのように私は、2つのスパンの間、私にテキストを提供するために、それを強制します「スパン」
私を返しますGETTAGNAME()関数にそれを変更した場合
?
Stakトレース:
org.openqa.selenium.WebDriverException: (WARNING: The server did not provide any stacktrace information)
Build info: version: '2.0rc3', revision: 'unknown', time: '2011-06-21 23:22:02'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_20'
Driver info: driver.version: RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:131)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:105)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:402)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:213)
at org.openqa.selenium.remote.RemoteWebElement.getText(RemoteWebElement.java:117)
at com.deutscheboerse.testing.AuctionsPage.showAuctionID(AuctionsPage.java:63)
がOK を解決し、私はこの問題を回避する素晴らしく、簡単に(とコードに短縮)を発見しました。私はオークションIDをspan要素であることを知っているAN私はIDがどうあるべきかを知っているので、私は今のXpathで探しています:
public AuctionTab showAuctionID(String auctionID){
try{
auctionRow = getRegulationUI().getDriver().findElement(By.xpath("//span[text()='"+auctionID+"']"));
}catch (NoSuchElementException e){
throw new NotFoundException("Auction ID "+ auctionID+ "was not found on first page");
}
auctionRow.click();
return new AuctionTab(this);
}
うれしいことですが、2.0rc3を使用しているようなスタックトレースから最新のバージョンのSelenium(前回チェックした2.16.1)を使用することをお勧めします。ときどき奇妙なエラーが修正されたバグになることがあります。 – prestomanifesto