1

I am trying to login to https://www.crowdmed.com/login using selenium.

This is the code I have so far. I am unable to login with my credentials. The error says "lable is not reachable by keyboard. When I try to use the name or id of the div, I get the error saying no such element found.

url ='https://www.crowdmed.com/case-selection?showCase=92447'
# This is what I really want to scrape
driver = webdriver.Firefox()
driver.get(url)

label = driver.find_element_by_xpath('//label["Email:"]')
#username = driver.find_element_by_name('Username')
#password = driver.find_element_by_id("password")
password = driver.find_element_by_xpath('//label["Password:"]')
label.send_keys("username")
password.send_keys("password")

driver.find_element_by_name("submit").click()

The corresponding error is

---------------------------------------------------------------------------
ElementNotInteractableException           Traceback (most recent call last)
C:\Users\ADMINI~1\AppData\Local\Temp/ipykernel_648/2975662060.py in <module>
      3 #password = driver.find_element_by_id("password")
      4 password = driver.find_element_by_xpath('//label["Password:"]')
----> 5 label.send_keys("voidyman")
      6 password.send_keys("S41r4m123")
      7 

C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py in send_keys(self, *value)
    475                 value = self._upload(local_file)
    476 
--> 477         self._execute(Command.SEND_KEYS_TO_ELEMENT,
    478                       {'text': "".join(keys_to_typing(value)),
    479                        'value': keys_to_typing(value)})

C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py in _execute(self, command, params)
    631             params = {}
    632         params['id'] = self._id
--> 633         return self._parent.execute(command, params)
    634 
    635     def find_element(self, by=By.ID, value=None):

C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in execute(self, driver_command, params)
    319         response = self.command_executor.execute(driver_command, params)
    320         if response:
--> 321             self.error_handler.check_response(response)
    322             response['value'] = self._unwrap_value(
    323                 response.get('value', None))

C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py in check_response(self, response)
    240                 alert_text = value['alert'].get('text')
    241             raise exception_class(message, screen, stacktrace, alert_text)
--> 242         raise exception_class(message, screen, stacktrace)
    243 
    244     def _value_or_default(self, obj, key, default):

ElementNotInteractableException: Message: Element <label> is not reachable by keyboard

When I try accessing by name or id as suggested on some other posts ( with the commented lines in my post), I get the following error. I have tried various combinations of "user", User" "username", "Username".

---------------------------------------------------------------------------
NoSuchElementException                    Traceback (most recent call last)
C:\Users\ADMINI~1\AppData\Local\Temp/ipykernel_648/3761058031.py in <module>
      1 label = driver.find_element_by_xpath('//label["Email:"]')
----> 2 username = driver.find_element_by_name('Username')
      3 password = driver.find_element_by_id("password")
      4 #password = driver.find_element_by_xpath('//label["Password:"]')
      5 label.send_keys("voidyman")

C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in find_element_by_name(self, name)
    494             element = driver.find_element_by_name('foo')
    495         """
--> 496         return self.find_element(by=By.NAME, value=name)
    497 
    498     def find_elements_by_name(self, name):

C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in find_element(self, by, value)
    974                 by = By.CSS_SELECTOR
    975                 value = '[name="%s"]' % value
--> 976         return self.execute(Command.FIND_ELEMENT, {
    977             'using': by,
    978             'value': value})['value']

C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in execute(self, driver_command, params)
    319         response = self.command_executor.execute(driver_command, params)
    320         if response:
--> 321             self.error_handler.check_response(response)
    322             response['value'] = self._unwrap_value(
    323                 response.get('value', None))

C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py in check_response(self, response)
    240                 alert_text = value['alert'].get('text')
    241             raise exception_class(message, screen, stacktrace, alert_text)
--> 242         raise exception_class(message, screen, stacktrace)
    243 
    244     def _value_or_default(self, obj, key, default):

NoSuchElementException: Message: Unable to locate element: [name="Username"]

1 Answer 1

1

You are using a wrong expression.
Generally //label["Email:"] is not a valid XPath expression.
To correctly and uniquely locate the username input field you can use something like this:

//div[@class="page-content"]//input[@ng-model="username"]

So your code line could be

username_input = driver.find_element_by_xpath('//div[@class="page-content"]//input[@ng-model="username"]')

You are also missing a wait there to make the page loaded before ayou going to access the elements there.
To do so it's recommended to use Expected Conditions explicit waits.
With it your code will be something like this:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

url ='https://www.crowdmed.com/case-selection?showCase=92447'
# This is what I really want to scrape
driver = webdriver.Firefox()
wait = WebDriverWait(driver, 20)

driver.get(url)

username_input = wait.until(EC.element_to_be_clickable((By.XPATH, '//div[@class="page-content"]//input[@ng-model="username"]')))

username_input.send_keys(username)

You can combine the 2 last lines in 1 by:

wait.until(EC.element_to_be_clickable((By.XPATH, '//div[@class="page-content"]//input[@ng-model="username"]'))).send_keys(username)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.