robot framework selenium get all names in a list - selenium

I'm fairly new to selenium. Please bear with me.
I have a html code as shown below. I'm producing only the relevant port.
<div id="id1" style="display: block;">
<ul>
<li id="id2" title="title1">
<ins class="icon"> </ins>
<a href="#" class="">
<ins class="icon"> </ins>
row1
</a>
</li>
<li id="id3" title="title2">
<ins class="icon"> </ins>
<a href="#" class="">
<ins class="icon"> </ins>
row2
</a>
</li>
.
.
.
</ul>
</div>
Using Robot framework selenium library, I have to display the names of the rows [row1, row2 etc...].
I am unable to find a suitable keyword which does this.

(note: the answer here refers to the original question. It was edited to ask something completely different so this answer no longer applies to the question in its present form)
You can use Get element count.
Using the html in the question as an example, it would look like this:
${count}= get element count //div[#id='id1']//li
That xpath says to find a div with the id "id1", then find any "li" elements anywhere under that div.

Related

Finding an element with a xpath that changes

Hello I am new to selenium and trying to find an element on a dropdown that expands to a list. The xpath constantly changes so cannot use it. Also tried the full xpath and did not work either. Other drop downs that I have used I have been able to use the cssselector but really do not have much to work with in here. I have tried with 'Account Maintenance' text but it did not work or did not do it properly. If I need to provide any additional information or more html please let me know.
<li class="k-item" role="treeitem" data-uid="706aa3e9-cd95-45c3-9ad0-e990887f9484" aria- selected="true" aria-expanded="false">
<div class="k-mid">
<span class="k-icon k-i-expand">
::before
</span>
<span class="k-in k-state-selected">Account Maintenance</span>
</div>
<ul "THIS IS THE LIST THAT EXPANDS AFTER CLICKING ON THE 'Acount Maintenance' text above but not my issue </ul>
</li>

PyCharm warn: Closing tag matches nothing for <p> tag

After inspect code from my PyCharm. It warns me as
Closing tag matches nothing at last </p> tag
But I didn't find any wrong my code. p tag is closed correctly.
<p v-if="files.length">
<ul>
<li v-for="file in files">
{{file.name}} <span v-if="file.success"> - success. </span><span v-if="file.error"> - fail. </span>
<span v-if="file.success || file.error">{{file.xhr.responseText}}</span>
</li>
</ul>
</p>
How can I resolve this warning correctly?
This warning is caused by invalid HTML. The ul element is not allowed within the p element. The warning may be resolved by refactoring the source to follow the HTML specification.
Remove p element:
<ul>
<li v-for="file in files">
{{file.name}} <span v-if="file.success"> - success. </span><span v-if="file.error"> - fail. </span>
<span v-if="file.success || file.error">{{file.xhr.responseText}}</span>
</li>
</ul>
Convert p element to div element:
<div v-if="files.length">
<ul>
<li v-for="file in files">
{{file.name}} <span v-if="file.success"> - success. </span><span v-if="file.error"> - fail. </span>
<span v-if="file.success || file.error">{{file.xhr.responseText}}</span>
</li>
</ul>
</div>
There is an excellent summary of the relevant portions of the spec in the answer https://stackoverflow.com/a/5681796. Note that the answer specifically addresses ol rather than ul, but is still applicable because their Categories and Content Model are the same.
It would be better if the PyCharm warning message was more specific. This can be done in the paid version of PyCharm via custom inspections, but is not possible in the Community Edition. https://www.jetbrains.com/help/pycharm/creating-custom-inspections.html
I have met this issue, too in my project.
My DOM structure is like:
<p>test<div>test2</div></p>
And, if i write the DOM structure as above, the WebStorm will alert 'closing tag matches nothing'
While, when i change this structure, e.g.: change the div block elements into inline elements span, then it works fine.
So, my advice is changing your DOM struture. e.g. Using div to replace p or using some inline elements in p tag.
One more thing, as i checked in this document https://www.w3.org/TR/html4/sgml/dtd.html
The doc said that the tag p normally includes inline elements. So, i think this is the root cause for your and my issues as mentioned above. So, using inline elements in tag p or use like div or other elements to replace tag p.

Selenium XPath of preceding element

I have a scenario wherein the html tags are generated dynamically through ajax as shown below
<div>
<span class="rptName">QLMS</span>
<span id="button_id_91">//generated dynamically
<span id="button_span_right_91">
<span id="button_91"/>
</span>
</span>
<span class="rptName">QLRS</span>
<span id="button_id_92">//generated dynamically
<span id="button_span_right_92">
<span id="button_92"/>
</span>
</span>
</div>
The span elements are generated dynamically, in such scenarios how do we get the xpath based on the text search(QLMS,QLRS present in span).
I need to do an click event on the
<span id="button_92" or "91"/>
Please let me know how to achieve in such scenario.
Seems pretty tricky. Using following-sibling should help. I am also filtering out the span with the partial id right. Try this:
//span[contains(text(),'QLRS')]/following-sibling::span//span[not(contains(#id,'right'))]

Click dynamic div of menubar which is loaded via jquery

Im using Selenium 2.44 library with IE 9 browser
The menubar is loaded dynamically via js.I tried to locate the element via findElement - used Xpath. It ends up in throwing nosuchElement exception. below is snippet of Dom element
<html><body class="page">
<div id="dynamicMenu" style="display: block;">
<ul class="sf-menu sf-js-enabled sf-shadow">
<li sequence="7">
<a class="sf-with-ul" href="UserContentStart.aspx?category=17">Type
<span class="sf-sub-indicator"> ยป</span></a>
<ul style="display: none; visibility: hidden;">
<li sequence="0">
Brochure
</li>
<li sequence="1">
Direct mail
</li>
<li sequence="2">
E-mail
</li>
<li sequence="3">
Flyer
</li>
<li sequence="4">
Poster
</li>
<li sequence="5">
Presentation
</li>
<li sequence="6">
Letter
</li>
</ul>
</li>
</ul>
</div>
</body></html>
Do I need to execute the javascript before finding the element.
I dont have access to source code.All I inspect is via DOM element source from F12 dev tool.
Thanks !
//li[#sequence='5']/a should work for you. And, before that you have to make sure the element is visible.
Below Code will find the 5th element and will wait untill it gets visible for 20 sec .
Once its visible it will click the element.
In your case 5th element is the link to 'Presentation' which is in 'a' tag.
WebDriverWait Test = new WebDriverWait(driver, 10);
WebElement Fifth_Link = Test.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(text(),'Presentation')]")));
Fifth_Link.click();
Let me know if it does not works.

Webdriver: How to select anchor link under DIV?

In below code when I use //a[text()='My Process1' in Firebug it evaluates xpath and returns correctly, however when I try to use the same for finding an element using WebDriver I get NoSuchElement exception....any ideas what I might be doing wrong?
<div class="abbd" style="">
<ul class="New-type">
<li class="abcmenuitem" id="yui-gen10" groupindex="0" index="3">My Process1</li>
<li class="abcmenuitem" id="yui-gen11" groupindex="0" index="4">My Process2</li>
</ul>
</div>
webDriver.findElment(By.linkText("My Process1"));