admin管理员组

文章数量:1333403

I used the same type of code to select the drop down there the code is working fine but in this case i tried to click on the button. am getting the error as Element is not currently visible and so may not be interacted with Command duration or timeout: 31 milliseconds

JavascriptExecutor executor3 = (JavascriptExecutor)driver;
executor3.executeScript("document.getElementById('iskpiFilterAction').style.display='block';");
driver.findElement(By.id("iskpiFilterAction")).click();
Thread.sleep(6000); 

The Problem is the type is hidden and the html tags as follows:

<input id="iskpiFilterAction" type="hidden" value="1" name="isKpiFilterAction">

Can any one please check the code and give me solution or sample code.

I used the same type of code to select the drop down there the code is working fine but in this case i tried to click on the button. am getting the error as Element is not currently visible and so may not be interacted with Command duration or timeout: 31 milliseconds

JavascriptExecutor executor3 = (JavascriptExecutor)driver;
executor3.executeScript("document.getElementById('iskpiFilterAction').style.display='block';");
driver.findElement(By.id("iskpiFilterAction")).click();
Thread.sleep(6000); 

The Problem is the type is hidden and the html tags as follows:

<input id="iskpiFilterAction" type="hidden" value="1" name="isKpiFilterAction">

Can any one please check the code and give me solution or sample code.

Share Improve this question asked Dec 5, 2013 at 2:48 testingtesting 1,79615 gold badges46 silver badges75 bronze badges 4
  • what in the world is ".style.type='hidden'"? Hidden inputs are not visible on the page, how would you click them???? – epascarello Commented Dec 5, 2013 at 2:50
  • Is there any way to click the button if it is hidden please suggest me a solution – testing Commented Dec 5, 2013 at 2:53
  • Please anyone give me some example for the above html tag – testing Commented Dec 5, 2013 at 3:28
  • 2 It is not a button. input type hidden is NOT a BUTTON – epascarello Commented Dec 5, 2013 at 3:51
Add a ment  | 

3 Answers 3

Reset to default 2

As epascarello mentioned in the ment, #iskpiFilterAction is not a button, it's a hidden <input> element. Therefore, you can't click() it here:

driver.findElement(By.id("iskpiFilterAction")).click(); // this won't work

Also, what people usually do with a element like that, which is either visible or not is use ExpectedCondition.visibilityOfElement() like so:

WebElement foo2 = wait.until(ExpectedConditions
      .visibilityOfElementLocated(By.id("iskpiFilterAction")));

Whereas, the regular way of getting a element might be:

WebElement foo2 = wait.until(ExpectedConditions
      .presenceOfElementLocated(By.id("iskpiFilterAction")));

You can try to use Selenuim Actions class to simulate user interactions which will make the button visible to the user--

for example:

WebElement menu = driver.findElement(By.xpath("));

    Actions build = new Actions(driver);
    build.moveToElement(menu).build().perform();//Hovers the mouse over the first element which will trigger the event
    WebElement m2m= driver.findElement(By.xpath(""));// finds the previouslly hidden element
    m2m.click();

本文标签: javascriptSelenium Webdriver Element is not currently visibleStack Overflow