Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何单击<;svg:image>;使用Selenium和Python的元素_Python_Selenium_Svg_Xpath_Webdriverwait - Fatal编程技术网

如何单击<;svg:image>;使用Selenium和Python的元素

如何单击<;svg:image>;使用Selenium和Python的元素,python,selenium,svg,xpath,webdriverwait,Python,Selenium,Svg,Xpath,Webdriverwait,下面提供了一个xpath: <svg:image xlink:href="some.svg" class="holder-38" width="24" height="268" preserveAspectRatio="none" x="426.7" y="473" type="image/svg+xml" data-ember-action="" data-ember-action-12238="12238"> 但无法使用标签作为svg:image访问: '//svg:image

下面提供了一个xpath:

<svg:image xlink:href="some.svg" class="holder-38" width="24" height="268" preserveAspectRatio="none" x="426.7" y="473" type="image/svg+xml" data-ember-action="" data-ember-action-12238="12238">
但无法使用标签作为svg:image访问:

'//svg:image[@class="holder-38"]'

如何在此处指定标记?

请尝试以下方法访问标记名称

'//*[local-name()="svg:image"][@class="holder-38"]'
要单击元素,请使用
Action
Class

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.common.action_chains import ActionChains
elememnt=WebDriverWait(driver, 10).until(ec.presence_of_element_located(("xpath", '//*[local-name()="svg:image"][@class="holder-38"]')))
ActionChains(driver).move_to_element(elememnt).click().perform()
元素包括SVG文档中的图像。它可以显示文件或其他SVG文件。SVG软件必须支持的唯一图像格式是JPEG、PNG和其他SVG文件。动画GIF行为未定义

一起显示的SVG文件不加载外部资源、样式,并且不能交互。要包含动态SVG元素,请尝试使用外部URL。要包含SVG文件并在其中运行脚本,请尝试在的内部

注意:HTML规范将
定义为解析HTML时的同义词。此特定元素及其行为仅适用于SVG文档或


xlink:href 该属性将指向资源的链接定义为引用。该链接的确切含义取决于使用它的每个元素的上下文

自SVG 2以来已弃用:不再推荐此功能。尽管某些浏览器可能仍然支持它,但它可能已经从相关的web标准中删除,可能正在被删除,或者可能仅出于兼容性目的而保留。避免使用,并尽可能更新现有代码;请参阅本页底部的兼容性表以指导您的决策。请注意,此功能可能随时停止工作

注意:SVG 2不再需要
xlink
名称空间,因此应该使用而不是
xlink:href


解决方案 要在所需元素上单击(),您需要引导WebDriverWait使所需的
元素可单击,并且可以使用以下解决方案:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[name()='svg:image' and starts-with(@class, 'holder') and contains(@xlink:href, 'some')]"))).click()
注意:您必须添加以下导入:

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

但我不想用*作为标签-你知道如何避免吗?我已经将你上次编辑的问题回滚,因此问题标题更通用,对社区和未来读者更有帮助。
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC