Rish
Rish

Reputation: 11

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

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?

Upvotes: 1

Views: 467

Answers (1)

Adonis Gaitatzis
Adonis Gaitatzis

Reputation: 3729

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(" ");

Upvotes: 1

Related Questions