I am trying to send keys on search bar from a column in a excel, it works fine previously but now it just return errors: object of type 'float' has no len().
Please find the code:
def search(key):
driver.get(url)
driver.find_element_by_xpath('//*[@id="searchCode"]').clear()
driver.implicitly_wait(10)
driver.find_element_by_xpath('//*[@id="searchCode"]').send_keys(key)
def get_keyword():
data = pd.read_excel('search.xlsx')
for d in data['code']:
search(d)
If I change to:
def search(key):
driver.get(url)
driver.find_element_by_xpath('//*[@id="searchCode"]').clear()
driver.implicitly_wait(10)
driver.find_element_by_xpath('//*[@id="searchCode"]').send_keys(str(key))
def get_keyword():
data = pd.read_excel('search.xlsx')
for d in data['code']:
search(d)
Then the search bar appears: 175717.0, but in excel, it is only 175717 and test format, it is a bit confusing...
Excel:(pretty sure no float value, and I convert to text format already
code
175717
175740
Could someone please help with this, thanks!
According to Selenium docs
send_keys(*value)[source]
Simulates typing into the element.
Args :
value - A string for typing, or setting form fields. For setting file inputs, this could be a local file path.
send_keys
accepts a str
not a float
So in your case you'd be replacing d
with str(d)
The error occurred because len returns the number of items in an object, which is not valid for a float
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.