Ayyappa Pusarla
Ayyappa Pusarla

Reputation: 50

I am not able to Iterate the Data in a webtable using selenium webdriver

List <WebElement> rnum = dr.findElements(By.xpath("//*[@id='leftcontainer']/table/tbody/tr"));
        for(int i=1;i<rnum.size();i++){

            List <WebElement> rowcells = dr.findElements(By.xpath("//*[@id='leftcontainer']/table/tbody/tr[rnum]/td"));

            for(int cnum=0;cnum<rowcells.size();cnum++){
                System.out.println(rowcells.get(cnum).getText());

            }

        }

when i ran this script it is throwing error

I tried it two times, but it's not working

Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died. Build info: version: '2.51.0', revision: '1af067d', time: '2016-02-05 19:11:55' System info: host: 'ULTP_374', ip: '192.168.111.89', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_75' Driver info: driver.version: RemoteWebDriver Session ID: 03c1856b-d233-403b-98fc-c765f056aa42 Capabilities [{platform=WINDOWS, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, nativeEvents=false, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=45.0.1}] at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:665) at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:388) at org.openqa.selenium.remote.RemoteWebDriver.findElementsByXPath(RemoteWebDriver.java:504) at org.openqa.selenium.By$ByXPath.findElements(By.java:356) at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:351)

Upvotes: 0

Views: 277

Answers (2)

Prashant Dhage
Prashant Dhage

Reputation: 57

Here's the answer for your webtable

List <WebElement> rnum = 
    dr.findElements(By.xpath("//*[@id='leftcontainer']/table/tbody/tr"));

for(int i=0; i<rnum.size(); i++){

    List <WebElement> rowcells = dr.findElements(By.xpath("//*[@id='leftcontainer']/table/tbody/tr[i]/td"));

    for(int cnum=0;cnum<rowcells.size();cnum++){
            System.out.println(rowcells.get(cnum).getText());
    }
}

The unreachable browser exception is for different reason. Your browser is not launched successfully.

Upvotes: 0

user3063502
user3063502

Reputation: 51

Issue seems to be that your server cannot communicate with the web browser: Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.

Looks like there is an active issue created for it: https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/4319

Upvotes: 0

Related Questions