-1

Windows 10Home x64 / Python 3.7.0 win64 / Selenium 3.14.0 / Geckodriver 3.14.0 / Firefox 61.0.2.

I'm trying to click on the login button, even though I have copied and pasted the full XPath I am not able to click the Login button.

from selenium import webdriver

driver = webdriver.Firefox()
driver.get('https://library.yonsei.ac.kr/')
linkElem = driver.find_element_by_link_text('LOGIN').click() 
username = driver.find_element_by_id('id')
username.send_keys('myuserAbc')
password = driver.find_element_by_id('password')
password.send_keys('mypass123')
linkElem = driver.find_element_by_xpath("/html/body/div[2]/div[2]/div/div[2]/form/fieldset/div[2]/p[@class='loginBtn']/input[@type='submit']").click()

Thank you for your help.

Update1: The script works up to the point of localizing the login button, I don't have problems with Marionette or having the latest Firefox version.

Update2: I added p[@class='loginBtn']/input[@type='submit'] in an effort to make it more specific but still doesn't work.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

2 Answers2

1

In my experience i have found that the button click might not work some times on form buttons with type set to action. The best possible way to work through this one will be to use the submit() method.

so something like this should work on your login form

from time import sleep
time.sleep(20) 
driver.find_element_by_class_name('loginBtn').submit()

This will submit the form to the server and you will be able to go through the login process.

if that doesn't work you could also try the follwoing

driver.find_element_by_class_name('loginBtn).send_keys(Keys.ENTER)

Now, why Button.click(); not working here could have following reasons.

1.The button is visible but not enabled.

2.Driver is finding the 2 instances of Button element

.More discussion about this can be found here Selenium: submit() works fine, but click() does not

Jishnu Ramesh
  • 617
  • 10
  • 17
  • Hi Jishnu, i tried the first command self.driver.click_element_by_class_name('loginBtn').submit() but got this error "self.driver.click_element_by_class_name('loginBtn').submit() NameError: name 'self' is not defined" how should I define self? – Andres Toro Aug 25 '18 at 06:43
  • Hi Jishnu, i tried the first command self.driver.click_element_by_class_name('loginBtn').submit() but got this error "self.driver.click_element_by_class_name('loginBtn').submit() NameError: name 'self' is not defined" how should I define self? Also tried this: linkElem = driver.click_element_by_class_name('loginBtn').submit() but got the following error: AttributeError: 'WebDriver' object has no attribute 'click_element_by_class_name' – Andres Toro Aug 25 '18 at 07:03
  • self is the reference to the current instance of a class. i see that you are not defining any classes. I have made a type in the answer. It has been updated and should work now – Jishnu Ramesh Aug 25 '18 at 10:29
  • Let me know if it works or if it is still giving you exceptions – Jishnu Ramesh Aug 25 '18 at 10:37
  • couldn't log in. – Andres Toro Aug 25 '18 at 11:17
  • What exception are you getting ? – Jishnu Ramesh Aug 25 '18 at 11:19
  • I couldn't log in. Got this error: return self._parent.execute(command, params) File "C:\Program Files\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute self.error_handler.check_response(response) File "C:\Program Files\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementNotInteractableException: Message: Element
  • is not reachable by keyboard
  • – Andres Toro Aug 25 '18 at 11:20
  • Is this the case with both submit() and send_keys() method ? – Jishnu Ramesh Aug 25 '18 at 11:31
  • with submit() i got this error: (...) line 628, in _execute return self._parent.execute(command, params) File "C:\Program Files\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute self.error_handler.check_response(response) File "C:\Program Files\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: ./ancestor-or-self::form – Andres Toro Aug 25 '18 at 11:53
  • i changed it to: import time time.sleep(20) driver.find_element_by_class_name('loginBtn').submit() but got this error: raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: ./ancestor-or-self::form – Andres Toro Aug 25 '18 at 12:21