Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/336.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
Java 如何使用SeleniumWebDriver定位自定义html元素_Java_Selenium_Svg_Webdriver - Fatal编程技术网

Java 如何使用SeleniumWebDriver定位自定义html元素

Java 如何使用SeleniumWebDriver定位自定义html元素,java,selenium,svg,webdriver,Java,Selenium,Svg,Webdriver,我有以下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-

我有以下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 @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);
应该也可以

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);