Reputation: 529
I am writing a selenium webdriver program using python.
My problem is that I am not able to click on the image by using x path or css path or id.
driver.find_element_by_xpath("/div/svg/g/g[3]/g/rect").click()
driver.find_element_by_css_selector(""div#servicecatalogdisplaygraph.x-component svg g g g rect")
My html page info is:
<div id="servicecatalogdisplaygraph" class="x-component graph x-border-item x-box-item x- component-default" style="background: none repeat scroll 0% 0% white; padding: 10px; overflow: auto; margin: 0px; width: 484px; left: 0px; top: 0px; height: 491px;">
<svg style="width: 100%; height: 100%; min-width: 89px; min-height: 422px;">
<g>
<g>
<g>
<g>
<g style="cursor: pointer;">
<image xlink:href="/images/mxgraph/link.png" style="pointer-events:none" x="42" y="202" width="16" height="16" stroke-width="1" transform=" scale(1 1) translate(0 0)">
<rect stroke="none" fill="none" visibility="hidden" pointer-events="fill" x="42" y="202" width="16" height="16" stroke-width="1">
</g>
</g>
Upvotes: 0
Views: 3635
Reputation: 15413
First tip: use shorter selector when possible, you don't need this overhead. Lets use you code example (I'm assuming by your dom that the elements are descendants), locating and clicking the image:
driver.find_element_by_css_selector("#servicecatalogdisplaygraph image").click()
or
driver.find_element_by_css_selector("#servicecatalogdisplaygraph rect").click()
Thats should work.
P.S. Be sure that the image element (or the rect one) is visible.
Upvotes: 1