How to select a field from html table using Selenium web driver in java -


in web page have html table , contains multiple radio button. want select 1 radio button. far able find values table not able select. code: getting error on syntax aname.click(); error "the method click() undefined type string"

import java.io.*; import org.openqa.selenium.support.ui.expectedconditions; import org.openqa.selenium.support.ui.select; import org.openqa.selenium.support.ui.webdriverwait; import org.openqa.selenium.by; import org.openqa.selenium.webdriver; import org.openqa.selenium.webelement; import org.openqa.selenium.ie.internetexplorerdriver; import java.util.list;   import java.util.concurrent.timeunit;        public class sendtxn1 {      static webdriver d1=null;          public static void main(string[] args) throws ioexception, interruptedexception         {         file file1=new file("c:\\selenium\\iedriverserver_win32_2.35.3\\iedriverserver.exe");         system.setproperty("webdriver.ie.driver",file1.getabsolutepath());          d1= new internetexplorerdriver();         d1.get("http://10.00.00.107/");                webelement table_element = d1.findelement(by.id("tblsendmoneypayoutagents"));              list<webelement> tbl_rows=table_element.findelements(by.xpath("id('tblsendmoneypayoutagents')/tbody/tr"));               system.out.println("number of rows in table = "+tbl_rows.size());              int row_num,col_num;              row_num=1;              col_num=1;              string aname;                    for(webelement trelement : tbl_rows)                  {                      list<webelement> tbl_col=trelement.findelements(by.xpath("td"));                           for(webelement tdelement : tbl_col)                          {                             aname = tdelement.gettext();                               if(aname.equals("vnm - vn shop herat"))                                        aname.click()l                              break;                                             system.out.println(aname);                             col_num++;                         }                          row_num++;                 }                          }     } 

i think need use executescript select radio button. method executes javascript string. think of doing eval, selenium. depending on version of selenium using, can cast webdriver javascriptexecutor, , call executescript, e.g.

((javascriptexecutor) d1).executescript("alert('replace alert code select radio button');"); 

edit

if don't want use executescript, need webelement corresponds radio button , call click method. in case, trying call click on string returned gettext, hence error :). missing 1 more step selects radio buttons table cell.

something along lines of (the xpath query might wrong)

list<webelement> radio_buttons = tdelement.findelements(by.xpath('input[type=radio]')); 

edit 2

to spell out answer in copy-paste-able form, replace

aname = tdelement.gettext(); if(aname.equals("vnm - vn shop herat"))   aname.click(); 

with

if(tdelement.gettext().equals("vnm - vn shop herat")) {    list<webelement> radio_buttons = tdelement.findelements(by.xpath('input[type=radio]'));    for(webelement radio : radio_buttons) {          //now check radio want click    } } 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -