0

I know this question has been asked a million times here and I have tried them all, I still can't get my python code to click a button!

So here's the result of the inspect element of said button: <input value="New Quote" class="btn" name="new_quote_wizard" title="New Quote" type="button" onclick="if (window.invokeOnClickJS_00bC0000001TjBl) window.invokeOnClickJS_00bC0000001TjBl(this); else if (parent.window.invokeOnClickJS_00bC0000001TjBl) parent.window.invokeOnClickJS_00bC0000001TjBl(this); return false">

I've tried this:

browser.find_element_by_name('New Quote').click() 

but it returns with this error:

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: [name="New Quote"]

What else can I do to click this one button?

4
  • 2
    a million times ... I have tried them all - pretty bold statement, since you are only giving one example you tried. ;-) But maybe you should not search for New Quote, which is the value, but rather for new_quote_wizard, which is the name.CommentedJun 22, 2017 at 10:41
  • Thanks @ChristianKönig! But unfortunately, I've tried that too and it also fails with a similar error message: selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: [name="new_quote_wizard"] I've also tried the browser.findElementByXpath("//input[@value='New Quote'][@title='New Quote']").click(); And for that it says it doesn't recognise the xpath command
    – Sean Low
    CommentedJun 22, 2017 at 10:43
  • Is the tag is inside any frame or iframe?CommentedJun 22, 2017 at 10:56
  • I don't think so, how can I be sure?
    – Sean Low
    CommentedJun 22, 2017 at 12:39

2 Answers 2

4

Looks like problem is in the selecting element by name providing value. Try this instead:

browser.find_element_by_name('new_quote_wizard').click() 
1
  • Thanks @peregrino! But I've tried that, too, and it comes up with the same error : selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: [name="new_quote_wizard"]
    – Sean Low
    CommentedJun 22, 2017 at 10:54
1

OK guys - I got it working through another stackoverflow question here: How do I click a button in a form using Selenium and Python 2.7?

So basically, I had to wait for the element!

I added these lines to my code:

wait = WebDriverWait(browser, 10) newQuote = wait.until(EC.presence_of_element_located((By.NAME, "new_quote_wizard"))) newQuote.click()

Thanks for all the help!

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.