Can t Click an Element in Python Selenium After Successfully Finding It

0 votes

I am using the following script to find elements called 'service_notes' and 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 log, the element is found, but for some reason I can't 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?

Here's the HTML of the link 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>

Oct 4, 2018 in Python by eatcodesleeprepeat
• 4,710 points
7,864 views

1 answer to this question.

+1 vote

I've encountered this problem of not being able to click on elements too. One way I found to go around it was to use execute_script method. In your case -

driver.execute_script("arguments[0].click();", service_notes[0])
answered Oct 4, 2018 by Priyaj
• 58,090 points
Just awesome.. thanks a lot..!
You are welcome, I am glad it helped.
Awesome buddy..i literally spent one whole day on this issue and couldn't fix it. I came close but not successful. Now I am good with your solution. keep it up

Hi,

Glad that you got the answer and it did work out for yours. You can upvote the answer if you found helpful. You can post any query of yours in the community forum.

Related Questions In Python

+4 votes
7 answers
0 votes
1 answer

How can I find out the index of an element from row and column in Python?

You probably want to use np.ravel_multi_index: [code] import numpy ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,720 points
2,017 views
0 votes
1 answer

Finding an index in Python

You can find the index in the ...READ MORE

answered Nov 19, 2018 in Python by SDeb
• 13,300 points
1,339 views
0 votes
1 answer

Is it possible to create an array with all values as zero in python?

You can use  np.zeros(4,3) This will create a 4 ...READ MORE

answered May 24, 2019 in Python by Anjali
858 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
12,615 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
8,571 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
6,629 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,517 views
0 votes
1 answer

Can't Click an Element in Python Selenium After Successfully Finding It

I've encountered this problem of not being ...READ MORE

answered Oct 8, 2018 in Python by Priyaj
• 58,090 points
781 views
+2 votes
3 answers

How can I play an audio file in the background using Python?

down voteacceptedFor windows: you could use  winsound.SND_ASYNC to play them ...READ MORE

answered Apr 4, 2018 in Python by charlie_brown
• 7,720 points
12,874 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