Search code examples
pythonseleniumselenium-webdriverwebdriver

How to use find element function of selenium in case of no attributes for name, id, class etc. in the HTML


I'm trying to make a automated login on a website using Selenium. I did everything except cant get to selenium write the login details in the appropriate boxes. Because the driver.find function cant find the specified element of the page or I just suck at it.

For reference I've attached the images for which I want to use the find element on(highlighted in the images):the part where e-mail is to be inserted by selenium

the part where password is to be inserted

Also need help in click function of selenium on the following:

Link here

I tried using driver find element function by class, class name but cannot understand which value do I have to insert. I did also use driver find elements but still didn't work either.


Solution

  • Try the below XPath expression for email field:

    //input[contains(@type,'email')]
    

    And below one for password:

    //input[contains(@type,'password')]
    

    driver.find_element() code would look like below:

    driver.find_element(By.XPATH,"//input[contains(@type,'email')]").send_keys("your email address here")
    driver.find_element(By.XPATH,"//input[contains(@type,'password')]").send_keys("your password here")