Issue
wait = WebDriverWait(driver, 5)
hobbies_xpath = f'//input[@type="checkbox"][@value="{row["Hobbies"]}"]/parent::div'
wait.until(EC.element_to_be_clickable((By.XPATH, hobbies_xpath))).click()
With this above code , I am not able to click on the Radio Button of this form https://demoqa.com/automation-practice-form. Its throwing error
'selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (578, 460). Other element would receive the click: ...'
Any possible solution would help.
I have tried below code as well.
input_hobbies= row['Hobbies']
for hobby in input_hobbies:
hobbies_xpath = f'//input[@type="checkbox"][@value="{hobby}"]'
driver.find_element(By.XPATH,hobbies_xpath).click()
Solution
Input is rendered backward (under) label
element. It's common situation for custom inputs in automation.
To click on checkbox you should click on label - it would trigger input check action.
For example, you can build xpath selector from element with class custom-checkbox
which contains any child with text that matches your hobby and get it's label
child.
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
url = "https://demoqa.com/automation-practice-form"
options = Options()
options.add_argument("start-maximized")
driver = webdriver.Chrome(options=options)
driver.get(url)
wait = WebDriverWait(driver, 10)
actions = ActionChains(driver)
hobbies = ['Sports', 'Reading', 'Music']
for hobby in hobbies:
wait.until(EC.presence_of_element_located(
(By.XPATH, f"//*[contains(@class, 'custom-checkbox') and .//*[contains(.,'{hobby}')]]//label"))).click()
Answered By - Yaroslavm
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.