Reputation: 471
I have such HTML:
upload_input = $driver.find_element(:id, "//input[@name = 'coupon_file']")
$driver.execute_script "$('input').show();"
upload_input.send_keys file
I'm trying to upload a file but get the error:
no such element: Unable to locate element
Upvotes: 0
Views: 249
Reputation: 23815
upload_input = $driver.find_element(:id, "//input[@name = 'coupon_file']")
Actually you're doing incorrect. You're trying to locate upload element using xpath
syntax but mentioned id
locator which is incorrect. It should be as below :-
upload_input = $driver.find_element(:xpath, "//input[@name = 'coupon_file']")
upload_input.send_keys file
Or you can easily locate this upload element using name
locator instead as :-
upload_input = $driver.find_element(:name, "coupon_file")
upload_input.send_keys file
Upvotes: 1