Unable to Click on an Element in Selenium (Python) even after finding it.

0 votes

Below is the script to find all elements called 'service_notes' and then click the first of them:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
import os

driver = webdriver.Firefox(executable_path=r'geckodriver.exe')

driver.get("https://.../sites/frontiersupport/servicenotes/Pages/default.aspx")
os.system("java -jar sikulix.jar -r login.sikuli")
driver.implicitly_wait(5) #
service_notes = driver.find_elements(By.XPATH, '//*/a[starts-with(@href, "/sites/frontiersupport/servicenotes/Lists/SNotes/DispForm.aspx")]')
print(str(service_notes[0]) + ' is the first service note')
print(len(service_notes))
service_notes[0].click()

According to the logs, even though the element is found, I;m unable to click it:

<selenium.webdriver.firefox.webelement.FirefoxWebElement (session="7505cfd0-5f41-4a8c-af28-bca639e13332", element="c81518a8-5f6c-42fa-8089-5f9469423d7c")> is the first service note
10
Traceback (most recent call last):
  File "scraper.py", line 19, in <module>
    service_notes[0].click()
  File "C:\Users\Joseph\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "C:\Users\Joseph\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webelement.py", line 628, in _execute
    return self._parent.execute(command, params)
  File "C:\Users\Joseph\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Joseph\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoAlertPresentException: Message: No modal dialog is currently open

The browser is defniitely open, and I'm not sure why the driver is looking for an open 'modal dialog'. This should simply be clicking a link. Any ideas?

This is the HTML of the link which I want to click:

<a onfocus="OnLink(this)" href="/sites/frontiersupport/servicenotes/Lists/SNotes/DispForm.aspx?ID=14686" onclick="GoToLink(this);return false;" target="_self">Firmware 3.04 released for the 850-DS <img src="/_layouts/images/blank.gif" class="ms-hidden" alt="Use SHIFT+ENTER to open the menu (new window)." width="1" height="1" border="0"></a>
Mar 30, 2018 in Selenium by Shubham
• 13,350 points
9,474 views

2 answers to this question.

0 votes

Even I encountered a simlar problem of not being able to click on elements. One way I found to go around this was to use execute_script method. So, the code in your case would be:-

driver.execute_script("arguments[0].click();", service_notes[0])
answered Mar 30, 2018 by nsv999
• 5,430 points
+1 vote

Here, I give you working script which select location.

from selenium import webdriver
import time

driver = webdriver.Chrome('./chromedriver.exe')
url="https://jenner.com/people"
try:
    driver.get(url)
    element = driver.find_element_by_xpath("//div[@class='filter offices']")
    element.click()
    time.sleep(5)
    element = driver.find_element_by_xpath("//input[@id='search_offices_chicago']")
    element.click()
    time.sleep(5)
except Exception as e:
    print e
    driver.quit()
driver.quit()
answered Sep 19, 2018 by Priyaj
• 57,300 points

very good.... I did just two slit change in order to work in my pc:

1) driver = webdriver.Chrome()
2) print(e)
Hi, your code worked well for me. Thank you.

Related Questions In Selenium

0 votes
1 answer

How to use JavaScript in selenium to click an Element?

Executing a click via JavaScript has some ...READ MORE

answered Apr 13, 2018 in Selenium by Shubham
• 13,350 points
15,659 views
+1 vote
2 answers
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,430 points
1,195 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,510 points
1,280 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,510 points
1,038 views
+1 vote
1 answer
+4 votes
3 answers

Verifying whether an element present or visible in selenium Webdriver

Below code will help you: To check Element ...READ MORE

answered Apr 17, 2018 in Selenium by king_kenny
• 3,650 points
19,607 views