简体   繁体   中英

How do I click a Javascript button on a webpage using python selenium

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?

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

browser.find_element_by_name('new_quote_wizard').click()

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM