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:
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?
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.
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.