-2

This question already has an answer here:

I have used find the element by Xpath in my code, I get the error as ElementNotVisible.

<div class="loginBtn">
    <input style="width: 59px; height: 20px" id="SubmitCreds" onclick="clkLgn()" type="submit" value="" name="SubmitCreds">
</div>

I try search the attribute value for id "SubmitCreds" its available in 3 different locations so used xpath.

marked as duplicate by Kate Paulk, IAmMilinPatel, Niels van Reijmersdal, Bharat Mane, ECiurleo Jul 28 '16 at 8:39

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    thats not the correct way to ask questions, you should share the HTML snippet with your Code that you have tried. Its very vague to answer these kind of questions. See this – Paras Jul 25 '16 at 8:50
  • put your line of code that you have tried. – Paras Jul 25 '16 at 10:44
  • 1
    this is a common question, you need to wait for the page to be loaded and/or for the element to be visible.you can find other similar questions if you do a search. – lauda Jul 25 '16 at 13:44
0

Selenium determines an element is visible or not by the following criteria (use a DOM inspector to determine what css applies to your element, make sure you look at computed style):

  • visibility != hidden
  • display != none (is also checked against every parent element)
  • opacity != 0 (this is not checked for clicking an element)
  • height and width are both > 0
  • for an input, the attribute type != hidden

Your element is matching one of those criteria. If you do not have the ability to change the styling of the element, here is how you can forcefully do it with javascript:

((JavascriptExecutor)driver).executeScript("arguments[0].checked = true;", inputElement);

But that won't fire a javascript event, if you depend on the change event for that input you'll have to fire it too (many ways to do that, easiest to use whatever javascript library is loaded on that page).

The source for the visibility check -

https://github.com/SeleniumHQ/selenium/blob/master/javascript/atoms/dom.js#L577

The WebDriver spec that defines this -

https://dvcs.w3.org/hg/webdriver/raw-file/tip/webdriver-spec.html#widl-WebElement-isDisplayed-boolean

Not the answer you're looking for? Browse other questions tagged or ask your own question.