java - How to get input value by using class? -
i using code below
webelement inputele = driver.findelement(by.classname("class_name")); string inputeleval = inputele.getattribute("value"); system.out.println(inputeleval);
but value empty
. html below.
<div id="main"> <div id="hiddenresult"> <div class="tech-blog-list"> <label for="question">1st question</label> <input id="txt60" class="form-control" type="text" value="sddf sd sdfsdf sdf sdfsdf sdfsdfsd fsd" /> </div> </div> <div class="pagination_main pull-left"> <div id="pagination"> <div class="pagination"> <a class="previous" onclick="previousbtnclickevent();" href="javascript:void(0)">previous</a> <a id="pg59" class="ep" onclick="paginationbtnclickevent(this);" href="javascript:void(0)" name="textbox">1</a> <a id="pg41" class="ep" onclick="paginationbtnclickevent(this);" href="javascript:void(0)" name="textbox">2</a> <a id="pg40" class="ep" onclick="paginationbtnclickevent(this);" href="javascript:void(0)" name="textarea">3</a> <a id="pg60" class="ep current" onclick="paginationbtnclickevent(this);" href="javascript:void(0)" name="textbox">4</a> </div> </div> </div> </div>
try using webdriverwait
wait until element loaded on page , visible below :-
webdriverwait wait = new webdriverwait(driver, 10); webelement inputele= wait.until(expectedconditions.visibilityofelementlocated(by.classname("class_name"))); string inputeleval = inputele.getattribute("value"); system.out.println(inputeleval);
note :-by.classname("class_name")
give element class attribute equal class_name
. make sure element want locate unique element class attribute equal class_name
otherwise wise give first element condition true.
hope work..:)
Comments
Post a Comment