java - Cannot interact with input (role=combobox) using Selenium WebDriver (Firefox) -
i'm studying selenium webdriver , testing skills on public site. issue cannot interact input element role='combobox' using selenium webdriver + java. need interact (select 2d option) first element of calculator ("Калькулятор"-"Тип расчета" - combobox near text). firefox shows code it:
<div class="select2-search"> <label class="select2-offscreen" for="s2id_autogen2_search"></label> <input id="s2id_autogen2_search" class="select2-input" type="text" aria-autocomplete="list" aria-expanded="true" role="combobox" spellcheck="false" autocapitalize="off" autocorrect="off" autocomplete="off" aria-owns="select2-results-2" placeholder="" aria-activedescendant="select2-result-label-17"></input>
when try click or sendkeys it writes element (both selects , selects2) not visible although visible , interactable manually. css not transformed. found js can change property make element visible, tried - , nothing changed, isdisplayed() shows false , cannot select 2d item of combobox.
here code (i have left main part)):
webdriver driver = new firefoxdriver(); driver.get("http://sberbank.ru/ru/person/credits/money/consumer_unsecured"); try{ thread.sleep(1500); }catch(exception e) {system.out.println("error in sleep.");} list<webelement> selects = driver.findelements(by.cssselector(".select2-search"));//(".select2-results")); list<webelement> selects2 = driver.findelements(by.xpath("//input[@class='select2-input']")); system.out.println("xpath: "+selects2.size()); javascriptexecutor js = (javascriptexecutor)driver; js.executescript("window.scrollto(0,1000);"); system.out.println("value:"+selects2.get(0).getattribute("value")); ((javascriptexecutor) driver).executescript("arguments[0].style.display='inline';arguments[0].style.visibility='visible';arguments[0].style.height = '20px';arguments[0].style.width = '80px';",selects2.get(0)); system.out.println("visible: "+selects2.get(0).isdisplayed()); system.out.println("enabled: "+selects2.get(0).isenabled()); system.out.println("height: "+selects2.get(0).getattribute("height")+",width: "+selects2.get(0).getattribute("width")); selects2.get(0).click(); selects2.get(0).sendkeys("По среднемесячному доходу");
it writes: xpath: 7 value: visible: false enabled: true height: 0,width: 0 exception in thread "main" org.openqa.selenium.elementnotvisibleexception: element not visible , may not interacted with
i tried trigger keyevent jquery didn't help:
((javascriptexecutor) driver) .executescript("var s=window.document.createelement('script');" + "s.src='d:\\data\\selenium\\jquery-1.11.3.min.js';" + "window.document.head.appendchild(s);"); ((javascriptexecutor)driver).executescript("arguments[0].focus();var e = jquery.event.trigger({ type : 'keypress', : 65 });arguments[0].trigger(e);", selects2.get(0));
it writes "exception in thread "main" org.openqa.selenium.webdriverexception: arguments[0].trigger not function"
please me fix code able set 2d item of combobox.
finally got working -
driver.get('http://sberbank.ru/ru/person/credits/money/consumer_unsecured') driver.find_element_by_xpath('//*[@id="s2id_autogen1"]/a').click() driver.find_element_by_xpath('//ul[@class="select2-results ps-container"]/li[2]').click()
Comments
Post a Comment