2012-01-11 14 views
8

ठीक है, मैं पूरी तरह से अनजान हूं: मेरे पास उस पृष्ठ पर टेबल है जहां प्रत्येक पंक्ति में सीएसएस आईडी एक से बढ़ी है। और मैं इस तालिका में नीलामी आईडी खोज रहा हूं और पिछले सेलेनियम परीक्षण के माध्यम से दर्ज नीलामी के साथ मेल खाता हूं। तो मेरा कोड इस प्रकार है:वेबड्राइवर 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(); 
    } 

जहां "नीलामी" पिछले परीक्षण द्वारा विधि को भेजी जाती है।

auctionRow Webelement दो फैला जहां वास्तविक auctionID संग्रहीत किया जाता है के साथ किया जाता है और

<span id="mainForm:aucPanelId:0:listOfAuctions:0">116</span> 

पूरी पंक्ति क्लिक करने योग्य है, इसलिए बाद मैं क्लिक() भेज आदेश, यह मेरे पाया नीलामी खुल जाएगा

अजीब क्या है: नीलामी Row.getText(); एक त्रुटि फेंकता है।

तो मैं 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) 

हल ठीक है, मैं अच्छा और आसान (और कम कोड के लिए) वैकल्पिक हल मिल गया। के बाद से मैं जानता हूँ कि नीलामी आईडी स्पान तत्व में है एक मुझे पता है कि आईडी होना चाहिए, मैं अब 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); 
    } 
+6

खुशी है कि आपने इसे हल किया है, एक साइड नोट के रूप में, मैं आपको अपने स्टैक ट्रेस से सेलेनियम (2.16.1 पिछली बार चेक की गई) के नवीनतम संस्करण का उपयोग करने की सलाह दूंगा, ऐसा लगता है कि आप 2.0rc3 का उपयोग कर रहे हैं। कभी-कभी अजीब त्रुटियां बग हो सकती हैं जिन्हें बाद में तय किया गया है। – prestomanifesto

उत्तर

0

के बजाय यह कर:

getDriver().findElement(By.xpath("//span[text()='"+auctionID+"']")); 

मैं कुछ कोशिश करेंगे इस तरह:

By auctionList = By.xpath(".//span[contains(@id,'listOfAuctions')]")); 
By containsTextWithId = By.xpath(".//span[contains(.,'" + id + "')]")); 
By combinedLocator = new ByChained(auctionList, containsTextWithId); 

या कुछ समान विचार, जो आप कर रहे हैं उसके आधार पर।

संबंधित मुद्दे