I have bar graph in a website and need to click on it. Using developer tools, I am getting below xpath:
/html/body/root/main/portal/div[2]/div/div/div/my-portal/div[3]/td-tyr/td-tyr/div[1]/filter-bar/div/div[3]/div[1]/div[1]/bar-chart/div/div[1]/div/svg/g[4]/g[1]/rect[1]
When using the above in xpath, it's giving invalid expression. Any help will be appreciated.
To click on the Bar Graph as the element have a parent
<svg>
element you can use either of the following Locator Strategies:Using
css_selector
:Using
xpath
:Ideally to click on a clickable element you need to induce WebDriverWait for the
element_to_be_clickable()
and you can use either of the following Locator Strategies:Using
CSS_SELECTOR
:Using
XPATH
:Note: You have to add the following imports :
References
You can find a couple of relevant discussions on interacting with SVG element in: