Selenium WebDriver with Java - how to add "else" condition -
i have code:
public void setlist(by localizator, string v_value { select some_list = new select(driver.findelement(localizator)); for(webelement position_list : some_list.getoptions()) { if(position_list.gettext().equalsignorecase(v_value)) { some_list.selectbyvisibletext(position_list.gettext()); break; } } }
how can add together condition: if selenium doesn't find position_list.gettext().equalsignorecase(v_value) scheme throw new runtimeexpression?
use iterator
instead of foreach
, provides hasnext()
method can check if dealing lastly element of list.
iterator<webelement> iterator = some_list.getoptions().iterator();
and instead of foreach:
while(iterator.hasnext()) { webelement current = iterator.next(); if(current.gettext().equalsignorecase(v_value)) { current.selectbyvisibletext(position_list.gettext()); break; } if(!iterator.hasnext()){ throw new runtimeexception(); } }
java selenium
No comments:
Post a Comment