简体   繁体   English

尽管硒不可见,如何忽略元素单击

[英]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.

相关问题 Selenium:让findElements等待可见元素,尽管存在不可见元素 - Selenium: Let findElements wait for visible element although invisible element exists 如何强制Selenium WebDriver点击当前不可见的元素? - How to force Selenium WebDriver to click on element which is not currently visible? 如何忽略硒中的隐藏元素 - How to ignore the hidden element in selenium 无法滚动和单击,因为元素在本机android移动应用程序的硒中不可见 - Unable to scroll and click, as element is not visible in selenium with native android mobile application 如果xpath返回2个WebElement,Selenium是否只能单击可见元素 - Can Selenium click only the visible element, if the xpath returns 2 WebElements 无法单击选项卡的子值,Selenium中出现“元素不可见”异常 - Unable to click on a sub value of a tab, getting 'element not visible' exception in Selenium 如何使元素在Selenium Java中可见 - How to make element visible in selenium java Selenium 找到元素但随机不点击一个元素,尽管它在 Firefox 上这么说 - Selenium finds element but randomly doesn't click an element although it says so on firefox 如何解决 ElementNotInteractableException:元素在 Selenium webdriver 中不可见? - How to resolve ElementNotInteractableException: Element is not visible in Selenium webdriver? 在使用Selenium和Java将鼠标悬停在ebay.com中的元素上之后,如何单击可见的元素 - How to click on an element which is visible after mouse hover over an element within ebay.com using Selenium and Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM