Selenium locate submit button

会有一股神秘感。 提交于 2019-12-24 16:53:19

问题


I am working on a selenium script in Python, where I am on this stage trying to locate a submit button.

HTML

<div class="submit-buttons">
<button class="submit" type="submit">Filter</button>
</div>

I've tried and this has not worked.
So I am out of solutions:

browser.find_element_by_partial_link_text('Filter').click()
browser.find_element_by_link_text('Filter').click()
browser.find_element_by_class_name('submit').click()

回答1:


Try xpath solution:

driver.find_element_by_xpath('//div[@class="submit-buttons"]/button[@class="submit"]')

If it is still not identifying, the element might be inside a frame, and you have to switch to that frame before finding the element.




回答2:


By link text or by partial link text locators are going to work with links only - a elements. Here you have a button. If you want to use the button text, use the following "by xpath" locator:

//button[. = "Filter"]



回答3:


This code should work :

driver.find_element_by_xpath('//button[text()='Filter']')



回答4:


driver.findElement(By.cssSelector("button[type=\"submit\"]")).click();


来源:https://stackoverflow.com/questions/34547370/selenium-locate-submit-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!