Home > Enterprise >  How to skim text from a placeholder?
How to skim text from a placeholder?

Time:12-05

I'm trying to skim the text from a placeholder textbox to automate some boring stuff at work. I've this is the last step in this little project of mine and I have no idea how to do it. It reads:

<div id = "fieldTarget">
<input name = "titleofbox" type = "text" placeholder = "some random stuff" readonly = "readonly" class = "ui-autocomplete-input" autocomplete= "off">

I've tried the following:

text = wd.find_element("xpath" , 'the xpath')

text = wd.find_element("xpath" , 'the xpath').get_attribute("value") 

I've also tried text, input and class instead of value.

CodePudding user response:

You can try and use get_attribute directly on the placeholder - eg:

yourElement.get_attribute('placeholder');

CodePudding user response:

You can do like below if, if you wan to get the attribute of the element

//import webdriver
from selenium import webdriver
 
//create webdriver object
driver = webdriver.Firefox()
 
//enter keyword to search
keyword = "geeksforgeeks"
 
//get geeksforgeeks.org
driver.get("https://www.geeksforgeeks.org/")
 
//get element
element = driver.find_element_by_link_text("Courses")
 
//get href attribute
print(element.get_attribute('href'))
  • Related