-1

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()
driver.get("https://www.quora.com")

After launching if somehow I know the xpath of this tag.

<input  
class="text header_login_text_box ignore_interaction" 
type="text" 
name="email" tabindex="1"
data-group="js-editable"
placeholder="Email"
w2cid="wZgD2YHa18" 
id="__w2_wZgD2YHa18_email">

I can extract attribute using selenium webdriver on python using the following command if I now the name of the attribute.

dict['attribute'] = driver.find_element_by_xpath(x_path).get_attribute(attribute)

so my output will be

dict = { 'attribute':value}

Please help me to figure out the way to extract all the attributes with its value even I don't known what are all the attributes it has. My expected output would be

dict = { "class" : "text header_login_text_box ignore_interaction" 
        "type" : "text" 
        "name":"email" 
         "tabindex" : "1"
        "data-group" : "js-editable"
        "placeholder" : "Email"
        "w2cid" : "wZgD2YHa18" 
        "id" : "__w2_wZgD2YHa18_email"
        }

I am not sure How far it is possible, but I am expecting like in dictionaries we can extract data even without knowing the keys. Thank you

3
  • Show how you tried Commented Dec 12, 2018 at 12:07
  • Check added link Commented Dec 13, 2018 at 8:22
  • @KasiVisvanathan You shouldn't edit the question after you receive well researched canonical answers from the contributors. Else the existing answers will no longer remain valid and may not be useful to the future readers. If your requirement have changed feel free to raise a new question. StackOverflow contributors will be happy to help you out. I have reverted back the question to it's original state. Commented Dec 13, 2018 at 9:07

3 Answers 3

2

To get placeholder attribute use get_attribute()

element.get_attribute('placeholder')
Sign up to request clarification or add additional context in comments.

Comments

0

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")

1 Comment

driver.find_element_by_xpath(xpath_input).get_attribute("placeholder") This is working
0

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.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.