2

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
1
  • before this i was using by.name however its not working neither i change to other to xpath method Commented Jul 15, 2015 at 3:31

2 Answers 2

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

Hi Saifur , its not working . still getting the same error
1

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.