[英]How to ignore element to click although not visible Selenium
I am working on selenium, while running Java code I tried to access a text box from the web page but selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with Command duration or timeout error. 我正在使用selenium,但是在运行Java代码时,我尝试从网页访问一个文本框,但是selenium.ElementNotVisibleException:元素当前不可见,因此可能无法与命令持续时间或超时错误进行交互。
HTML code for text field : 文本字段的HTML代码:
<input type="text" name="TotalTaxPercent" id="TotalTaxPercent" value="19.00" class="smallinputField rightAlign" size="7" onblur="javascript:validateDecimal(this, 5)">
JAVA Code to access text field : JAVA代码访问文本字段:
public void setItemTaxValue( String value){
//By writableTag = By.name("TotalTaxPercent");
By writableTag = By.xpath("//a[contains(@title,'Override total tax percent')]");
this.sleep(3);
if (this.waitForExistence(writableTag,35)) {
this.textfieldSetText(writableTag, value);
clickOnOK ();
//
} else{
JLog.fail("Unable to find a writable item taxdialog!");
}
}
Error Tree : 错误树:
[2015-07-14 20:18:34 PDT] Switch to Frame: <top>
[2015-07-14 20:19:22 PDT] Setting TextField (By.name: TotalTaxPercent) with data: 10
[2015-07-14 20:19:24 PDT] Screen Capture: C:\source\selenium-main\selenium-vodafone\target\capture\screenCapture_20150714201922308.jpg
[2015-07-14 20:19:24 PDT] FAIL: org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 40 milliseconds
Kindly advise , Thanks you 请告知,谢谢
Probably do entire action using JavaScript since it is a hidden field 由于它是一个隐藏字段,因此可能使用JavaScript进行整个操作
String script = "document.getElementById('TotalTaxPercent').setAttribute('value','20.00');";
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript(script);
If JQuery is an option then try 如果可以选择JQuery,请尝试
String script = "$('#TotalTaxPercent').prop('value', 20.00);";
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript(script);
Just catch the Exception: 只需捕获异常:
try {
this.textfieldSetText(writableTag, value);
} catch (ElementNotVisibleException e) {
JLog.fail("Unable to find a writable item taxdialog!");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.