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.
HTML code for text field :
<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 :
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
Saifur
16.3k7 gold badges51 silver badges74 bronze badges
asked Jul 15, 2015 at 3:31
-
before this i was using by.name however its not working neither i change to other to xpath methodDamon Ng– Damon Ng2015年07月15日 03:31:55 +00:00Commented Jul 15, 2015 at 3:31
2 Answers 2
Probably do entire action using JavaScript since it is a hidden field
String script = "document.getElementById('TotalTaxPercent').setAttribute('value','20.00');";
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript(script);
If JQuery is an option then try
String script = "$('#TotalTaxPercent').prop('value', 20.00);";
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript(script);
answered Jul 15, 2015 at 3:43
1 Comment
Damon Ng
Hi Saifur , its not working . still getting the same error
Just catch the Exception:
try {
this.textfieldSetText(writableTag, value);
} catch (ElementNotVisibleException e) {
JLog.fail("Unable to find a writable item taxdialog!");
}
answered Jul 15, 2015 at 6:41
Comments
default