Extracting Placeholder From Html Tag Using Python Selenium
I am using the following python code to launch the Firefox webpage. from selenium import webdriver from selenium.webdriver.common.keys import Keys driver= webdriver.Firefox() drive
Solution 1:
To get placeholder
attribute use get_attribute()
element.get_attribute('placeholder')
Solution 2:
Define the xpath of the input tag which you wish to extract the placeholder.
xpath_input = "//input[@id='__w2_wZgD2YHa18_email']"
driver.find_element_by_xpath(xpath_input)
After get the element, you can extract placeholder
("Email") by get_attribute("placeholder")
Solution 3:
To extract the placeholder text i.e. Email you need to induce WebDriverWait for the desired element to be clickable and then use get_attribute()
method as follows:
Line of Code:
print(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='text header_login_text_box ignore_interaction' and @name='email']"))).get_attribute("placeholder"))
Console Output:
Email
Note : You have to add the following imports :
from selenium.webdriver.support.uiimportWebDriverWaitfrom selenium.webdriver.common.byimportByfrom selenium.webdriver.supportimport expected_conditions asEC
Post a Comment for "Extracting Placeholder From Html Tag Using Python Selenium"