【问题标题】:How to locate custom html elements using selenium webdriver如何使用 selenium webdriver 定位自定义 html 元素
【发布时间】:2012-11-22 00:57:27
【问题描述】:

我有以下html代码

  <svg height="600" width="910" xmlns:xlink="http://www.w3.org/1999/xlink"  
   id="svgcontent" overflow="visible" x="910" y="600" viewBox="0 0 910 600">
    <g style="pointer-events:all">
      <text fill="rgb(0,0,0)" font-family="Sans-Serif" font-size="13" id="80-155-126" 
        transform="rotate(-90, 168, 126)" y="126" x="168" style="pointer-
         events:inherit">A100A</text>
   </g>
  </svg>

我尝试了以下方法但没有成功

assertEquals(driver.findElements(By.xpath("//*[local-name()='svg' 
 and namespace-uri()='http://www.w3.org/2000/svg' and @id='svgcontent']//*[local-
 name()='g' and namespace-uri()='http://www.w3.org/2000/svg']/text")).size(), 1);

【问题讨论】:

    标签: java selenium svg webdriver


    【解决方案1】:

    尝试关注

    assertEquals(driver.findElements(By.xpath("//*[local-name()='svg' and @id='svgcontent']//*[local-name()='text']")).size(), 1); 
    

    应该可以,但是

    assertEquals(driver.findElements(By.xpath("//*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg' and @id='svgcontent']//*[local-name()='g' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='text']")).size(), 1);
    

    应该也可以。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-15
      • 1970-01-01
      • 2013-01-12
      • 2020-01-09
      相关资源
      最近更新 更多