I've been searching for how to solve this but can't seem to find anything that works for me. Hope someone can help.
I'm on a website using python and selenium chrome browser and trying to log into a website which has the following HTML where you enter the username or email:
Email or username
Email or username
I can't select this input using the ID or name as the number is different everytime, so I want to select the input box using the placeholder="Email or username".
Each time I select this placement and try to enter some string I receive an error saying:
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
Which seems to be because of the type="hidden".
Any ideas on how to select this and enter text?
I am currently using the following code to select the placeholder, which is giving the error:
driver.find_element_by_xpath("//input[@placeholder='Email or username']").send_keys("email")
I'm sure sure whether the element is really hidden as I can select the element using the following (once the ID is available):
driver.find_element_by_xpath("//*[@id='1986367435']").send_keys("email")
Many thanks for your help.
解决方案
Target input field has no type="hidden" attribute. It might be not visible initially after page redirection, so you can try to use ExplicitWait to solve this issue:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH,'//input[@placeholder="Email or username"]')))