-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

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Show how you tried – Andersson Dec 12 '18 at 12:07
  • Check added link – Andersson Dec 13 '18 at 08: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. – undetected Selenium Dec 13 '18 at 09:07

3 Answers3

2

To get placeholder attribute use get_attribute()

element.get_attribute('placeholder')
ewwink
  • 18,382
  • 2
  • 44
  • 54
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")

ryan.tran
  • 91
  • 1
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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352