我正在研究Selenium WebDriver并在公共网站上测试我的技能。问题是我无法使用Selenium WebDriver + Java与role ='combobox'交互输入元素。 我需要为计算器的第一个元素(“Калькулятор” - “Типрасчета” - 本文附近的组合框)进行交互(选择2d选项)。 Firefox显示了它的代码:
<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>
当我尝试单击或发送键时,它会写入该元素(选择和选择2)虽然可见且可手动交互,但不可见。 CSS没有转变。我发现JS可以更改属性以使元素可见,但我尝试了 - 没有任何改变,isDisplayed()显示为false,我无法选择组合框的2d项。
这是代码(我只剩下主要部分)):
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("По среднемесячному доходу");
它写道: xpath:7 值: 可见:错误 启用:true 高度:0,宽度:0 线程“main”中的异常org.openqa.selenium.ElementNotVisibleException:元素当前不可见,因此可能无法与
进行交互我也尝试使用JQuery触发keyevent,但它没有帮助:
((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', which : 65 });arguments[0].trigger(e);", selects2.get(0));
它写道“线程中的异常”主“org.openqa.selenium.WebDriverException:arguments [0] .trigger不是函数”
请帮我修改我的代码,以便能够设置此组合框的第2项。
答案 0 :(得分:0)
终于搞定了 -
public function up()
{
Schema::create('responders', function (Blueprint $table) {
$table->increments('id');
$table->string('user_id');
$table->string('responder_id');
$table->integer('incident_id');
$table->foreign('incident_id')->references('incident_id')->on('incidents');
$table->double('last_lat', 10, 6);
$table->double('last_lng', 10, 6);
$table->timestamps();
});
}