Issue
An "Agree with the terms" button appears on https://www.sreality.cz/hledani/prodej/domy I am trying to go through that with a .click() using Selenium and Python. The button element is:
<button data-testid="button-agree" type="button" class="scmp-btn scmp-btn--default w-button--footer sm:scmp-ml-sm md:scmp-ml-md lg:scmp-ml-dialog">SouhlasĂm</button>
My approach is:
driver = webdriver.Chrome()
driver.implicitly_wait(20)
driver.get("https://www.sreality.cz/hledani/prodej/domy")
button = driver.find_element_by_css_selector("button[data-testid='button-agree']")
button.click()
Any idea what to change to make it work? Thanks! :)
Solution
Check the below working workaround solution:
driver = webdriver.Chrome()
driver.implicitly_wait(10)
driver.get("https://www.sreality.cz/hledani/prodej/domy")
driver.maximize_window()
# Below line creates instance of ActionChains class
action = ActionChains(driver)
# Below line locates and stores an element which is outside the shadow-root
element_outside_shadow = driver.find_element(By.XPATH, "//div[@class='szn-cmp-dialog-container']")
# Below 2 lines clicks on the browser at an offset of co-ordinates x=5 and y=5
action.move_to_element_with_offset(element_outside_shadow, 5, 5)
action.click()
# Below 2 lines presses TAB key 9 times so that pointer moves to "SouhlasĂm" button and presses ENTER key once
action.send_keys(Keys.TAB * 9).perform()
action.send_keys(Keys.ENTER).perform()
Imports required:
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
NOTE:
- This is a workaround solution, as there is no direct selenium solution to handle it.
Answered By - Shawn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.