Cannot store attribute using Selenium IDE

女生的网名这么多〃 提交于 2019-12-24 13:29:32

问题


I have the following XML structure:

<array-list>
<tests>
<test myId="11">Some data</test>
<test myId="22">Some data 2</test>
</tests>
</array-list>

How can I store "myId" attribute of the first element in the list?

I have tried storeAttribute command with the following location parameters with no luck:

 1. //array-list/tests/test[1]@myId 
 2. xpath=//array-list/tests/test[1]@myId
 3. */test[1]@myId
 4. //array-list/tests/test@myId
 5. //array-list/tests/test[1]/@myId
 6. //array-list/tests/test/@myId

I believe there were some other attempts as well but none of them are working. Please do not say "correct XML". XML does not have any other attributes. That is retrieved from external service which I cannot modify. So the only question is how to get **myId** attribute from the fist test tag in the list


回答1:


You will not be happy if I say to correct xml but You have to change myID to myid(all in small)(I am still in search for the reason why?).

I tried with the given xml

<array-list>
<tests>
<test myid="11">Some data</test>
<test myid="22">Some data 2</test>
</tests>
</array-list>

The code I tried is

<tr>
<td>storeAttribute</td>
<td>//test[1]/@myid</td>
<td>myVar</td>
</tr>
<tr>
<td>echo</td>
<td>${myVar}</td>
<td></td>
</tr>

and it worked well.




回答2:


So for example using css selector assuming the following changes:

<array-list>
<tests>
<test id="11">Some data</test>
<test id="22">Some data 2<img src="some attribute"></test>
</tests>
</array-list>

We could do something like this:

And the html:

<tr>
    <td>storeText</td>
    <td>css=test#11 </td>
    <td>var</td>
</tr>
<tr>
    <td>echo</td>
    <td>${var}</td>
    <td></td>
</tr>
<tr>
    <td>storeAttribute</td>
    <td>css=test#22 &gt; img@src</td>
    <td>img</td>
</tr>
<tr>
    <td>echo</td>
    <td>${img}</td>
    <td></td>
</tr>

And the webdriver python version:

    var = driver.find_element_by_css_selector("test#11").text
    print(var)
    img = driver.find_element_by_css_selector("test#22 > img").get_attribute("src")
    print(img)


来源:https://stackoverflow.com/questions/13637094/cannot-store-attribute-using-selenium-ide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!