2012-12-04 71 views
0

我有以下的HTML代码如何使用硒找到自定义HTML元素的webdriver

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

回答

2

尝试以下

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

应该也可以。