Mabel
Mabel

Reputation: 13

Python - How to send numerical values via Selenium Send Keys

I have an Excel spreadsheet that has numerical values that I am trying to type into the Bing search engine via Selenium Send Keys. Whenever I try to run the code it gives me an error

TypeError: object of type 'numpy.int64' has no len()

I am able to send alphanumeric strings and alphabetical strings but just not numerical values alone. How can I resolve this?

data = pd.read_excel(excel_file, sheet_name= "Sample")
value1 = data["Number"][1]
browser.get('https://www.bing.com')
browser.find_element_by_xpath('//*[@id="sb_form_q"]').send_keys(value1)

Upvotes: 1

Views: 725

Answers (1)

JeffC
JeffC

Reputation: 25611

When you enter keys into an INPUT or any other tag type on the webpage, you are entering text (string) and not an int anyway. Just either change the type to string in your Excel sheet or convert it to string when you .send_keys().

browser.find_element_by_xpath('//*[@id="sb_form_q"]').send_keys(str(value1))

BTW, if you are going to have an XPath locator that just looks for an ID, you should use .find_element_by_id("sb_form_q"). It will be faster, easier to read, better supported, etc.

Upvotes: 1

Related Questions