Selenium click is not working with this one "document.getElementById("submitMe").click()"

351 Views Asked by At

I'm facing issue while click on the submit button using selenium webdriver also unable to click on the the web page button dynamically. I'm using selenium chrome webdriver, have tried below options as well,

driver.find_element_by_xpath('//*[@id="get"]').click()
driver.execute_script('document.getElementById("submitMe").click()')

but still it won't help me to get resolve the issue. can someone please help me to get it run or suggest me if you have any alternative?

1

There are 1 best solutions below

0
On

Try grabbing the element reference through Selenium and then passing that as an argument the JavaScript executor to click()

element = driver.find_element_by_xpath("//*[@id='get']")
driver.execute_script("return arguments[0].click()", element);

I've never tried this, but if this is a link, button, or other form input, I think you could also focus the element and try to pass a space to it to emulate a keyboard interaction. It should act the same as "tabbing to the link and pressing space"

# grab element
element = driver.find_element_by_xpath("//*[@id='get']")
# focus
driver.execute_script("return arguments[0].focus()", element);
# send "space"
element.sendKeys(" ");