如何在selenium webdriver中启用输入元素? [英] How to wait for input element enabled in selenium webdriver?

查看:145
本文介绍了如何在selenium webdriver中启用输入元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写脚本在JIRA中的屏幕下方选择并输入值。




'问题类型'是一个具有自动完成属性的'input'元素:



< input type =textautocomplete =offrole =comboboxaria -autocomplete =listaria-haspopup =truearia-expanded =falseclass =text aui-ss-field ajs-dirty-warning-exemptid =issuetype-fieldaria-controls =issuetype -suggestions>



输入'input type ',其他领域如总结灰色几秒钟。如果我试图为'summary'字段输入值,请使用以下代码:

  myDriver.findElement(By.id 摘要))的SendKeys(摘要)。 

汇总字段不会被输入,而是会出现错误元素未在缓存中找到 - 可能是页面已经改变了,因为它被抬起来......会发生。

'summary'字段的HTML代码是:

 < input type =textvalue =name =summaryid =summaryclass =text long-field>   $ b  

所以我想要的只是等待'summary'输入字段被启用

然后发送密钥给它。我正在寻找类似于

  ExpectedConditions.presenceOfElementLocated 

,但是我希望'启用',而不是 presenceOfElementLocated visibilityOfElementLocated 。我不想使用 Thread.sleep()



有什么建议?

解决方案 $>

elementToBeClickable 检查元素是否已启用。

https:/ /seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html#elementToBeClickable-org.openqa.selenium.By-


I am writing script to select and enter value in below screen in JIRA.

The 'issue type' is an 'input' element with autocomplete property:

<input type="text" autocomplete="off" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-expanded="false" class="text aui-ss-field ajs-dirty-warning-exempt" id="issuetype-field" aria-controls="issuetype-suggestions">

Right after entering value for 'input type', the rest of fields such as 'summary' grey out for a few seconds. If I try to enter value for 'summary' field right after, using following code:

myDriver.findElement(By.id("summary")).sendKeys(summary);

summary field will not be entered, rather an error "Element not found in the cache - perhaps the page has changed since it was looked up.." will happen.

HTML code for 'summary' field is:

<input type="text" value="" name="summary" id="summary" class="text long-field">

So what i want is just to wait for 'summary' input field to be enabled and then sendkey to it. I am looking for something like

ExpectedConditions.presenceOfElementLocated 

but instead i want 'enabled', not presenceOfElementLocated or visibilityOfElementLocated. I do not want to use Thread.sleep() either.

Any suggestions?

解决方案

How about ExpectedConditions.elementToBeClickable(locator)?

elementToBeClickable checks if the element is enabled.

https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html#elementToBeClickable-org.openqa.selenium.By-

这篇关于如何在selenium webdriver中启用输入元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆