-1

I'm learning automation with selenium and I'm a bit blocked at the moment with one element. I don't know why it is considered as not visible but elements similar to this one on another part of the website are considered as visible and I don't experience any issue to click on them.

To present you the concerned part, this is how it looks:

Calendar

It's a calendar with different shifts, there are three separated parts.

When I try to click on the orange shift, I have an error which tells me that this element isn't visible. But on my other scripts which perform the same kind of action but on the other shifts it works well

My script is the following one:

    # Check if the shift is on the schedule or not.
if (len(admin.find_elements_by_xpath("//div[@data-shift-date='%s']/div/div[@class='shift-details']" %date))!=0 ):
   print "The unassigned shift is scheduled, good"
else:
   print "The unassigned shift is not scheduled, issue"
   sauce_client.jobs.update_job(admin.session_id, passed=False)
   admin.quit();
   sys.exit()

# The part above works
# Publish the shift
# Open the shift
element = admin.find_element_by_xpath("//div[@data-shift-date='%s']/div/div[@class='shift-details']" %date)
actions.move_to_element(element)
actions.click(element)
actions.perform()
admin.implicitly_wait(10)

Even if I try this way it doesn't work:

# Publish the shift
# Open the shift
admin.find_element_by_xpath("//div[@data-shift-date='%s']/div/div[@class='shift-details']" %date).click()
admin.implicitly_wait(10)

The HTML of the orange element is the following one: HTML code

The error:

Traceback (most recent call last):
  File ".\Unassigned_shift_basics.py", line 84, in <module>
    admin.find_element_by_xpath("//div[@data-shift-date='%s']" %date).click()
  File "C:\Python27\lib\site-packages\selenium-3.0.2-py2.7.egg\selenium\webdriver\remote\webelement.py", line 77, in cli
ck
    self._execute(Command.CLICK_ELEMENT)
  File "C:\Python27\lib\site-packages\selenium-3.0.2-py2.7.egg\selenium\webdriver\remote\webelement.py", line 494, in _e
xecute
    return self._parent.execute(command, params)
  File "C:\Python27\lib\site-packages\selenium-3.0.2-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 236, in exe
cute
    self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium-3.0.2-py2.7.egg\selenium\webdriver\remote\errorhandler.py", line 192, in
check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
  (Session info: chrome=55.0.2883.75)
  (Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Mac OS X 10.11.6 x86_64)
6
  • Have you try to record the same steps using selenium IDE?
    – ChathuD
    Commented Feb 16, 2017 at 14:07
  • Yes and it works but the issue with the IDE is that it points the dynamic id to click on this shift..
    – LeBrequin
    Commented Feb 16, 2017 at 14:13
  • Can you give the full error message? Are you creating that shift before you are trying to click it?
    – Swagin9
    Commented Feb 16, 2017 at 14:34
  • Yes the shift is created before by the script; But I have also tried when I have created it manually and it doesn't work: I add the error message to the post
    – LeBrequin
    Commented Feb 16, 2017 at 14:44
  • Are you sure date is what you think it is?
    – ernie
    Commented Feb 16, 2017 at 18:41

4 Answers 4

0

You can use javascript click event for the same. Let me know if you need further help. You can find answer here.

0

Try resizing the window.
We've had tests fail because the window size was too small.

0

After some research with the xpath finder on Chrome, I noticed that my xpath was pointing two version of the element, an invisible version and then the visible one. So my script was trying to click on something invisible which explains the error.

The way to tackle that was to reach the visible and click on it. To do that I have used find_elements_by_xpath to gather all these elements and then I have performed a click() on the second element which is the visible one.

0

Click on the any other element on the page. Then use TAB key to navigate to the exact element you want to click . Then hot enter from the keyboard. Hope this will work.

3
  • Hum I don't think it's possible, you can't really select this element by pressing TAB
    – LeBrequin
    Commented Feb 16, 2017 at 15:02
  • Just try , every element on a web page have a TAB index.So use that tab index to locate the element you want to click.
    – ChathuD
    Commented Feb 16, 2017 at 15:54
  • Ok I will try that
    – LeBrequin
    Commented Feb 16, 2017 at 15:55

Your Answer

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

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