简体   繁体   中英

How to "find" this Button with Selenium?

i´d like to click this button in my webdriver window with selenium. Most of the time i am using find_element_by_id, but how can I locate this one?

<button role="button" data-testid="uc-accept-all-button" class="sc-gsDKAQ cYtWkK" style="margin: 4px 0px;">accept all</button>

Tried xpath, name and class already like below

driver.findElement(By.xpath("//*[text()='accept all']")).click()
driver.find_element_by_class_name("sc-gsDKAQ cYtWkK").click()

I would go with this:

 document.querySelector("[data-testid='uc-accept-all-button']").click();
 <button role="button" data-testid="uc-accept-all-button" class="sc-gsDKAQ cYtWkK" style="margin: 4px 0px;" onclick="console.log('thank you')">accept all</button>

For use by Selenium: (not tested but should work)

driver.find_element_by_css_selector("[data-testid='uc-accept-all-button']");

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