gpt4 book ai didi

python - 如何通过Selenium-Python访问 'rect'类型元素

转载 作者:行者123 更新时间:2023-11-30 21:56:24 31 4
gpt4 key购买 nike

dom中有一个rect对象:

<rect class="slv-blank" id="id123" height="8.8" stroke-width="1px" width="18.8" x="59.2" y="37.5"></rect>

我正在尝试使用以下代码搜索它:

WebDriverWait(driver, 1).until(ec.presence_of_element_located(("xpath", '//rect[@id="id123"]'))).click()

这不起作用。

但以下情况确实如此:

WebDriverWait(driver, 1).until(ec.presence_of_element_located(("xpath", '//*[name()="rect"][@id="id123"]'))).click()

有什么线索可以解释为什么第一个不起作用吗?

最佳答案

<rect>

<rect> 元素是基本的SVG创建矩形的形状,由矩形的角位置、宽度和高度定义。矩形的角可以是圆角的。

示例:

<svg viewBox="0 0 220 100" xmlns="http://www.w3.org/2000/svg">
<!-- Simple rect element -->
<rect x="0" y="0" width="100" height="100" />

<!-- Rounded corner rect element -->
<rect x="120" y="0" width="100" height="100" rx="15" ry="15" />
</svg>
<小时/>

属性

attributes<rect>要素如下:

  • x :该属性决定矩形的x坐标。
    • 值类型:| ;默认值:0;可动画:是
  • y :该属性决定矩形的 y 坐标。
    • 值类型:| ;默认值:0;可动画:是
  • width :该属性决定矩形的宽度。
    • 值类型:自动|| ;默认值:自动;可动画:是
  • height :该属性决定矩形的高度。
    • 值类型:自动|| ;默认值:自动;可动画:是
  • rx :该属性决定矩形的水平角半径。
    • 值类型:自动|| ;默认值:自动;可动画:是
  • ry :该属性决定矩形的垂直角半径。
    • 值类型:自动|| ;默认值:自动;可动画:是
  • pathLength :此属性可以指定路径的总长度(以用户单位为单位)。
    • 值类型:;默认值:无;可动画:是

Note: Starting with SVG2 x, y, width, height, rx and ry are Geometry Properties, meaning those attributes can also be used as CSS properties for that element.

<小时/>

这个用例

作为<rect>元素是一个 SVG 元素,因此要找到此类元素,您必须显式指定 SVG namespace使用 访问元素时如下:

  • 对于 <svg>元素:

    //*[name()="svg"]
  • 对于 <g>元素:

    //*[name()="svg"]/*[name()="g"]
  • 对于 <rect>元素:

    //*[name()="svg"]/*[name()="g"]/*[name()="rect"]
    //*[name()="svg"]/*[name()="rect"]
<小时/>

引用文献

您可以在

中找到一些相关的详细讨论

关于python - 如何通过Selenium-Python访问 'rect'类型元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55490461/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com