java - how to insert value in multiple text box in selenium webdriver -
this java code
package com.ej.zob.modules; import org.openqa.selenium.by; public class setexchange { public void execute(string countryname, string value) { launchapplication.driver.findelement(by.linktext("set")).click(); launchapplication.driver.findelement(by.linktext("exchange rate")).click(); //launchapplication.driver.findelement(by.id("new_afghanistan_afn")).sendkeys(value); launchapplication.driver.findelement(by.xpath("//input[@maxlength='4']")).sendkeys(value); launchapplication.driver.findelement(by.xpath("//input[@value='set']")).click(); } }
this html
<div style="display: table-cell;width:270px" name="cell"> <input id="new_afghanistan_afn" type="text" maxlength="4"> <input type="button" value="set" onclick="setexchangerate('afghanistan','afn')" name="save"> <div id="msg_afghanistan_afn"></div> </div>
there more 100 textbox in webpage , same number of button in front of textbox.i want insert value in 100 textbox sequentially , click on button.but above code able insert value in single text box , click on single button. question how insert value text box , click on multiple button.each text box having different id if use findelement(by.id) code longer.
if buttons , textboxes surrounded same div, can search these like:
list<webelement> divs = launchapplication.driver.findelements(by.name("cell"));
note findelements returns elements match criteria.
then can loop through results this:
for(webelement elem: divs){ elem.findelement(by.cssselector("[type=text]")).sendkeys("your keys send"); elem.findelement(by.cssselector("[type=button]")).click(); }
this select first textfield , button of each div name cell. maybe need check if other divs called "cell" not holding these elements.
if don't know cssselectors
these match attribute text. more info here http://www.w3schools.com/cssref/css_selectors.asp
another way read in / or create list of ids , elements in loop.
does you, if not please feel free comment
Comments
Post a Comment