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.
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:
JavaScript
x
6
1
temp = driver.find_element_by_xpath("//div[@id='gridContainer']//div[@class='grid x0 y0']")
2
hat= ActionChains(driver).move_to_element(temp).click()
3
time.sleep(10)
4
button = driver.find_element_by_xpath("//a[@id='ccSelectDesignButton']")
5
hat.click(button).perform()
6
But every time I get this error:
JavaScript
1
2
1
Unable to locate element: {"method":"xpath","selector":"//a[@id='ccSelectDesignButton']"}
2
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?
Advertisement
Answer
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.
JavaScript
1
6
1
temp = driver.find_element_by_xpath("//div[@id='gridContainer']//div[@class='grid x0 y0']")
2
ActionChains(driver).move_to_element(temp).perform()
3
time.sleep(2)
4
button = driver.find_element_by_xpath("//a[@id='ccSelectDesignButton']")
5
ActionChains(driver).move_to_element(button).click(button).perform()
6
If this not resolved to your query please share the link.