1

On the website, the input tag is this:

<input value="Submit" type="submit">

How can I make selenium select this input button?

I tried this:

browser.find_element_by_css_selector("input[value='submit']")

But it wasn't able to find the input button.

3
  • use beautifulSoup ; for a in soup.find_all('input',{'value','Submit'}): ; print(a.get('type')) Commented Aug 13, 2018 at 23:55
  • For my project I have to use selenium Commented Aug 14, 2018 at 0:32
  • 1
    Should capitalize Submit, rather than submit? Commented Aug 14, 2018 at 2:21

3 Answers 3

1

I would use this xpath to find the above input:

browser.find_element_by_xpath(".//input[@value='Submit' and @type='submit']")

If there are multiple inputs with the same attributes, you may need to find by index as well.

UPDATE:

Since you are having trouble finding the element, and there are no iframes on the page, I would suggest using WebDriverWait in case there are any AJAX/JavaScript/Dynamic load events that are creating the input after the pageload is complete.

Import these into your script:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

Then try this:

wait = WebDriverWait(browser, 10)
wait.until(EC.element_to_be_clickable((By.XPATH, ".//input[@value='Submit' and @type='submit']"))).click()

As mentioned in your comment, you had to switch to a new tab. The way to do this in Selenium is:

#this will switch to the newest tab
browser.switch_to_window(browser.window_handles[-1])
Sign up to request clarification or add additional context in comments.

9 Comments

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":" .//input[@value='Submit' and @type='submit']"} Not working
Do you see an iframe or frame anywhere in the HTML?
No iframes on the page
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/support/wait.py", line 80, i n until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: No exception message. Still not working
Is the site public? Can you share the URL?
|
0

Please make sure that input tag is in the an iframe?

if it in an iframe you should use

browser.switch_to.frame('iframe's id') to enter the iframe, if you enter this frame, you can use xpath or css selector to find the tag you want.

Comments

0

There's a clear mispelling, the 'Submit' value has a capitalised S in your sourcecode, but you have provided lowercase in your selector. Try this instead!

browser.find_element_by_css_selector("input[value='Submit']")

Comments

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.