2016-05-05 57 views
0

以下のXMLコードでrect ID値を検索しようとしていますが、空リストとして取得しようとしています。これについてのどんな助けもありがとう!!!!! > driver.find_elements_by_xpathを( "/働い -Python Selenium Webdriverを使用してSVG要素を見つけることができません

driver.find_element_by_xpath( "//オブジェクト[ID @ = 'nodia']"):クロムとFirefoxの両方で全て以下Possibiltiesが試さ

<object id="nodia" 
< svg id="svg2" xmlns:svg='http://www.w3.org/2000/svg'> 
    < g id="layer1> 
    <image id="image3022"></image> 
    <rect id="rect8696"></rect> 
    <rect id="rect8996-6" ></rect> 
    </g> 
</svg> 
</object> 

/[ローカル名()= 'svg'とnamespace-uri()= 'http://www.w3.org/2000/svg'] ") - >空リストを返します driver.find_elements_by_xpath(" // [local-name()= 'svg' ] ") - >返す driver.find_elements_by_xpath(" //オブジェクト[@ id = 'nodia']/svg ") - >空リストを返します

答えて

0

は、XPathで各rect要素のid属性を取得するには、次の

for e in driver.find_elements_by_css_selector("#svg2 rect") : 
    print e.get_attribute("id") 
+0

driver.find_elements_by_xpath(「ID( 'svg2')// * [名:

for e in driver.find_elements_by_xpath("id('svg2')//*[name()='rect']") : print e.get_attribute("id") 

またはCSSセレクタと

()= 'rect'] ")は、rectのid値ではなく空のリストを返します。これで助けてください! –

関連する問題