I admit I’m not a programmer – I’ve been piecing together code from various posts/videos to scrape a website. I’ve gotten stuck on one line of code for hours now and cannot seem to get syntax right for a xpath or CSS solution.
The issue: I’m trying to send keys to a login menu which asks for an email and a password. My code is working for the password; however, I can’t get the keys to send for the email part of the login. I noticed the website script that the attributes for the email element are the same as another element except for the placeholder attribute. So this is my suspicion to why my code doesn’t work. However, when I try using xpath or CSS to locate the element via its placeholder attribute, I can’t seem to get the syntax right. I see so many varying syntax on different posts and I don’t know the coding language well enough to find my way through it all. I would appreciate any help!
FYI – I’m using Thonny and importing selenium.
website script
My code using Thonny as my code interface and importing selenium
The code for the password is working but the code for the email is not. Error codes:
username.send_keys("drew")
self._execute(
return self._parent.execute(command, params)
self.error_handler.check_response(response)
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
Here are some of my sorry attempts at using CSS and xpath to find the element via its placeholder attribute:
username = page_to_scrape.find_element(By.CSS_SELECTOR,"Type in your email")
username = page_to_scrape.find_element(By.CSS_SELECTOR("input[placeholder='Type in your email']"))
username = page_to_scrape.find_element(By.xpath("//input[contains(@placeholder,'Type in your password']"))
Again, I’m not a programmer so I may need fairly detailed syntax responses :// Thank you!
DMILLI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.