简体   繁体   中英

Click on button element without id/name using Python and selenium webdriver

I'm using Python and selenium to scan a web page and I want to click on a button that looks like this:

Later>

which is defined as:

<div class=”later___16eg8 col-xs-3of12”>
  <button class=”visible-xs-inline visible-sm-inline visible-md-inline bdp___2gfNX textButton___ETrkF” data-test=”later-small-button”> == $0
     “Later”
    <span aria-hidden=”true”>></span>
  </button>
  <button class=”visible-lg-inline visible-xl-inline bdp___2gfNX textButton___ETrkF” data-test=”later-large-button”> 
     “Later”
    <span aria-hidden=”true”>></span>
  </button>
</div>

I tried:

later = driver.find_element_by_xpath('//button[text()="Later"]')
later.click()

and while the first line finds the button (or part of it), the second generates the following error: selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

I also tried:

later = driver.find_element_by_xpath('//button[text()="Later>"]')

and this generated the following error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//button[text()="Later>"]"}

Any ideas?

Thanks

Have u tried //div[@class='later___16eg8 col-xs-3of12']/button/button[text()='Later']

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