简体   繁体   中英

How do I click on a button that has no ID or HTML using Python Selenium?

I have a script written and have been able to code for buttons that have html but this button that I inspected on this link, doesn't have one.

This is the element for the login button.

<input type="submit" value="login" class="button">

How would I write this line of script to click on this button using selenium & python?

To click on the button with text as Login you can use the following line of code :

browser.find_element_by_xpath("//form[@method='post' and @action='/auth/login/']//input[@class='button' and @value='login']").click()
#or
browser.find_element_by_xpath("//form[@method='post' and @action='/auth/login/']//input[@class='button' and @value='login']").submit()

your element has few attributes, which we can use. Try to find an element which starts with input and has an attribute type='submit'

driver.find_element_by_xpath("//div[@class='content']//input[@type='submit']").click()

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