find submit button in selenium without id

前端 未结 3 1264
独厮守ぢ
独厮守ぢ 2020-12-31 05:46

I have a button


I cannot fin

3条回答
  •  清歌不尽
    2020-12-31 06:33

    There are many options here, to name a few:

    If class alone is unique, you can use

    driver.find_element_by_css_selector(".button_main").click()
    

    If class + value combo is unique, you can use:

    driver.find_element_by_css_selector(".button_main[value='something']").click()
    

    You can also use xpath:

    driver.find_element_by_xpath("//input[@type='submit' and @value='something']").click()
    

    If none of those work (i.e. they are not identifying button uniquely), look at the elements above the button (for example ) and provide the xpath in format:

    driver.find_element_by_xpath("//unique_parent//input[@type="submit" and @value='something']").click()
    

提交回复
热议问题