0

I have such HTML:

enter image description here

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

2
  • Welcome to Stack Overflow. Please read "minimal reproducible example". Don't use a link to point to information used to help define or demonstrate the problem. Links rot then break, resulting in questions that make no sense. Instead, reduce the input the bare minimum then add it to your question, formatted appropriately. Commented Oct 20, 2016 at 0:56
  • Take a look at this answer Commented Oct 20, 2016 at 0:56

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot Saurabh, you are absolutely right!!!(Also thank you for editing my question and making it look nice cause I'm new to stackoveroflow)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.