'How can i use slenium in Python to click the button?
I try to find how can I click on button for accept cookies with a python in selenium,
I used a lot of convinations but nothing works :(
This is the element:
<button class="button primary cookie-button" ng-click="$ctrl.allowAllCookies()">
<span class="ng-binding">Todas las cookies</span>
</button>
I used in other with:
wait = WebDriverWait(driver, 5)
time.sleep(2)
wait.until(EC.presence_of_element_located((By.ID, "onetrust-banner-sdk")))
element = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="onetrust-accept-btn-handler"]')))
element.click()
This is all the code from button:
<div class="text-center cookie-controls"> <button class="button primary cookie-button" ng-click="$ctrl.allowCookiesSelection()"> <span class="ng-binding">Permitir selección</span> </button> <button class="button primary cookie-button" ng-click="$ctrl.allowAllCookies()"> <span class="ng-binding">Todas las cookies</span>
But now I don't have id to use and I don't know how can I use.
Solution 1:[1]
Accordingly to XML you presenting in the question you can locate this button with several XPath locators.
For example try this:
wait = WebDriverWait(driver, 20)
wait.until(EC.element_to_be_clickable((By.XPATH, '//button[contains(@ng-click,"allowAllCookies")]'))).click()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Prophet |
