0

I need to click on the element that has the following code

<img src="images/myImage.png" style="cursor:pointer;" onclick="ToggleAdvanceSection();ShowModal();" alt=""> 

this element is visible on the screen. it is an image. once clicked, a modal widow shows up

I tried

driver.findElement(By.xpath("//*[@onclick='ToggleAdvanceSection();ShowModal();']")).click();

However it throws an error : not visible . I made sure that the page is loaded . . still the same thing

How to click this element ?

5
  • We can't click element which is not visible. What is the error/output you get? Commented Aug 20, 2014 at 5:15
  • it is visible . inspect element in chrome shows this element Commented Aug 20, 2014 at 5:18
  • Inspect will show all the elements, but in order to click the element through selenium, the element needs to be visible (check the property of the element after it is initialized). In your post you mentioned it is not visible? Commented Aug 20, 2014 at 5:22
  • apologies, i meant it throws an error : element is not visible Commented Aug 20, 2014 at 5:24
  • Please provide your full HTML snippet. I guess there are many elements that have the same xpath and the 1st element is not visible. And, your needed image is not the 1st one. Commented Aug 20, 2014 at 7:24

1 Answer 1

1

Selenium would not be able to click the element if the element is not visible. This is by design.

Sign up to request clarification or add additional context in comments.

2 Comments

this element is visible on the screen. it is an image. once clicked, a modal widow shows up
There are two different things here. 1. All the elements are visible in the HTML when we inspect through any browser. 2. For each element (or for its parent) there would be a style property associated whether the element is visible or not as part of code. So selenium would use that property before clicking an element.

Your Answer

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.