无法通过Kendo UI图表上的xpath定位SVG元素 [英] Unable to locate SVG elements through xpath on Kendo UI chart

查看:108
本文介绍了无法通过Kendo UI图表上的xpath定位SVG元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实尝试了一些xpath,但是似乎没有运气.

I did try some of xpaths but seems no luck.

我要单击国家,然后单击图形,如下屏幕截图所示:

I want to click on country and then graph , Given below screenshot :

网站URL是: https://demos.telerik.com/kendo -ui/bar-charts/column

我尝试了xpaths:

I tried xpaths :

//text(text()='India')


 //g//text(text()='India')

推荐答案

所需的元素是 SVG元素,您需要考虑名称空间,并诱导 WebDriverWait 以使所需的元素可点击,然后单击首先在图形中的 bar 上,您可以使用以下解决方案:

As the desired elements are SVG Elements you need to consider the namespace and induce WebDriverWait for the desired element to be clickable and to click on the first bar within the graph you can use the following solution:

  • 代码块:

  • Code Block:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get("https://demos.telerik.com/kendo-ui/bar-charts/column")
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[@id='chart']//*[name()='svg']//*[name()='g']//*[text()='India']//following::*[name()='path']"))).click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[@id='chart']//*[name()='svg']//*[name()='g'][contains(@clip-path, 'url')]//*[name()='path']"))).click()

  • 浏览器快照:

  • Browser Snapshot:

    这篇关于无法通过Kendo UI图表上的xpath定位SVG元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆