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,490 points
24,105 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])


Hope this Helps!!

To learn more, join the online course to do Masters in Python.

Thanks!

answered Mar 30, 2018 by nsv999
• 5,500 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
• 58,060 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
5 answers

How to use JavaScript in selenium to click an Element?

WebElement element = driver.findElement(By.id("id")); JavascriptExe ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
70,330 views
+1 vote
2 answers

Is it possible to scroll down in a webpage using selenium webdriver programmed on python?

I using next code for facebook for ...READ MORE

answered May 16, 2019 in Selenium by mslavikas@gmail.com
26,063 views
0 votes
2 answers

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,500 points
13,616 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,115 views
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,910 points
7,204 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,854 views
+1 vote
1 answer
+3 votes
6 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,710 points
97,032 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP