java - Selenium Webdriver - How to click on ''Update icon'' in a grid table -
this code click on 'update icon' of specific record grid view using selenium webdriver (java)
i have written following code click on 'update icon' :-(this code working fine)
//this count total no of rows in grid:- list<webelement> count=driver.findelements(by.xpath(".//*[@id='ctl00_contentplaceholder1_gvcustomerdetails']/tbody/tr")); int totalnorecords=count.size(); system.out.println("total no of rows "+totalnorecords); //this find particular record in webtable po name selenium_testing11selenium_testing12 webelement record=driver.findelement(by.xpath(".//*[@id='ctl00_contentplaceholder1_gvcustomerdetails']/tbody/tr/following::td[text()='selenium_testing11']")); string poname= record.gettext(); //this verify if po name equals click on update icon else print else message if(poname.equals("selenium_testing11")){ webelement updatebtn=driver.findelement(by.xpath(".//*[@id='ctl00_contentplaceholder1_gvcustomerdetails']/tbody/tr/following::td[text()='selenium_testing11']/preceding-sibling::td//a[contains (@id,'btnupdate')]")); updatebtn.click(); } else system.out.println("po not exists");
string xpath = "//table[contains(@id, 'gvcustomerdetails')]" + "//tr[@class][td[5][text()='%s']]/td[2]/a"; public void clickediticon(string po) { driver.findelement(by.xpath(string.format(xpath, po))).click(); }
xpath explain:
//table[contains(@id, 'gvcustomerdetails')]
locator table
//tr[@class]
means find rows not header column row
[td[5][text()='%s']]
qualifier on tr find tr 5th cell's text equal argument:po, td[5]
means column: po
/td[2]
means find 2th cell(update icon inside it) matched row
/a
means find update icon link inside matched cell
Comments
Post a Comment