Home > OS >  XPATH function not recognizing textfield
XPATH function not recognizing textfield

Time:12-02

I'm a beginner to python and Selenium and am trying to create a basic code to auto login to a site for me.

https://www.faceit.com/en/login

In tutorials I've found online, ID's make it easier to identify the element, however, the page above doesn't have an ID so I've resorted to using XPATH as a means of identifying the element.

Is there something wrong with my XPATH formatting or something within the code that is causing the issue of not printing my text at all in the fields and subsequently not logging me in?

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

PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)

driver.get("https://www.faceit.com/en/login")
email_textbox = driver.find_element_by_xpath("//input[@type='email']")
email_textbox.send_keys("emailx")

password_textbox = driver.find_element_by_xpath("//input[@type='password']")
password_textbox.send_keys("passwordx")

login_button = driver.find_element_by_xpath("//button[@type='submit']")
login_button.click()

CodePudding user response:

probably you have to wait until your elements will be on their place. Try time.sleep(Some kind of time) or try with one of functions from documentation :) https://selenium-python.readthedocs.io/waits.html

Solution: In browser open developer tools and there is a option button "select an element in the page to inspect it" insepct element you want and in dev tools click right button on it and copy Xpath :)

If this help Vote me up! :)

CodePudding user response:

The XPath which you have used in your script are correct and good but looks like the elements were not loaded within the default wait time. So here you can add some wait time before finding these elements. Also to verify and generating the xpaths you can use the SelectorsHub browser plugin.

  • Related