1

My situation is that there is a grid of elements and on the hover of each element a button appears which you can click on then. enter image description here

See the difference between class="grid x0 y0" and class="grid x1 y0". id="ccSelectDesignButton" only appears on hover. I want to click on first element.

The code I am using is:

temp = driver.find_element_by_xpath("//div[@id='gridContainer']//div[@class='grid x0 y0']")
hat= ActionChains(driver).move_to_element(temp).click()
time.sleep(10)
button = driver.find_element_by_xpath("//a[@id='ccSelectDesignButton']")
hat.click(button).perform()

But every time I get this error:

 Unable to locate element: {"method":"xpath","selector":"//a[@id='ccSelectDesignButton']"}

I tried many other ways to locate it as well but still, I am unable to find and click it. Can anyone give me a better idea on how to deal with this?

2 Answers 2

1

I think for mouse-over event you need to use perform() and once done you can able to select desire button element and click on that.

temp = driver.find_element_by_xpath("//div[@id='gridContainer']//div[@class='grid x0 y0']")
ActionChains(driver).move_to_element(temp).perform()
time.sleep(2)
button = driver.find_element_by_xpath("//a[@id='ccSelectDesignButton']")
ActionChains(driver).move_to_element(button).click(button).perform()

If this not resolved to your query please share the link.

Sign up to request clarification or add additional context in comments.

Comments

0

Try to click element with javascript, like that:

driver.execute_script('$("a#ccSelectDesignButton").click();')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.