Unable to click on list element from drop down - ruby

Using Selenium WebDriver, I'm trying to click on Manual Testing option from Testing menu from http://guru99.com/ Manual Testing option appears after hovering mouse on Testing. In order to achieve above, I did following -
testing = $driver.find_element(:xpath, "//li[#class='item118 parent']")
mt = $driver.find_element(:xpath, "//li[#class='item119']/a")
$driver.action.move_to(testing).move_to(mt).perform
mt.click
But, sometimes error for line #3 above code -
Selenium::WebDriver::Error::MoveTargetOutOfBoundsError: Offset within element ca
nnot be scrolled into view: (85, 21): http://guru99.com/software-testing.html
and sometimes error for line #4 in above code -
Selenium::WebDriver::Error::ElementNotVisibleError: Element is not currently vis
ible and so may not be interacted with
Please help me to resolve this issue without executing javascript.
Here is HTML code -
<li class="item118 parent">
<a class="item" href="/software-testing.html"> Testing </a>
<span class="dropdown-spacer"></span>
<div class="dropdown columns-1 " style="width:180px;">
<div class="column col1" style="width:180px;">
<ul class="l2">
<li class="item119">
<a class="item" href="/software-testing.html"> Manual Testing </a>
</li>
.
.
.

You can try with partial_link_text:
testing = $driver.find_element(:partial_link_text, "Testing")
$driver.action.move_to(testing).perform
mt = $driver.find_element(:partial_link_text, "Manual Testing")
mt.click

Related

After parsing a valid expression, there is still more data in the expression pageCount

I'm making an E-commerce website and in the products section (inside admin), I was trying to display only 10 products per page. I'm new to Spring and while writing the code, I encountered an error (given in title) when trying to add the next page button. However, the code works fine with the Previous button and all the page numbers. Here's my code for the pagnation section:
<nav class="mt-3" th:if="${count > perPage}">
<ul class="pagination">
<li class="page-item" th:if="${page > 0}">
<a th:href="#{${#httpServletRequest.requestURI}} + '?page=__${page-1}__'" class="page-link">Previous</a>
</li>
<li class="page-item" th:each="number: ${#numbers.sequence(0, pageCount-1)}" th:classappend="${page==number} ? 'active' : ''">
<a th:href="#{${#httpServletRequest.requestURI}} + '?page=__${number}__'" class="page-link" th:text="${number+1}"></a>
</li>
<li class="page-item" th:if="${page pageCount-1}">
<a th:href="#{${#httpServletRequest.requestURI}} + '?page=__${page+1}__'" class="page-link">Next</a>
</li>
</ul>
</nav>
The first 2 li's work fine and I get the list of pages and also the previous button. But on adding the Next button, I get the error mentioned above.
First of all, please always provide the actual error message. Otherwise we are just guessing.
My guess is that th:if expects a boolean expression and what you have doesn't look like boolean to me: th:if="${page pageCount-1}"
Change that to something like page == pageCount-1, but again depends on what you want to display there

Generating correct url for page link

I have implemented pagation in my Spring boot application. There are no problems in the logic of it, however I am running into a weird issue with Thymeleaf.
Right now if I go to the following url
http://localhost:8080/Phoenix-listings
and if I hover my mouse over the link to page 2 is
http://localhost:8080/2
which is the wrong link, but if I manually go to the following url
http://localhost:8080/Phoenix-listings/1
then if I hover my mouse over page 2, then the link is
http://localhost:8080/Phoenix-listings/2
which is how it should be.
How can I make the correct link get generated even if I am in http://localhost:8080/Phoenix-listings?
Below is the section related to my pagation in Thymeleaf
<div class="row">
<div th:if="${ads.totalPages != 1}"
class="form-group col-md-11 pagination-centered">
<ul class="pagination">
<li th:class="${ads.number == 0} ? disabled"><a
class="pageLink" th:href="1">«</a></li>
<li th:class="${ads.number == 0} ? disabled"><a
class="pageLink" th:href="${ads.number}">←</a></li>
<li
th:class="${ads.number == (page - 1)} ? 'active pointer-disabled'"
th:each="page : ${#numbers.sequence(pager.startPage, pager.endPage)}">
<a class="pageLink" th:href="${page}" th:text="${page}"></a>
</li>
<li th:class="${ads.number + 1 == ads.totalPages} ? disabled">
<a class="pageLink" th:href="${ads.number + 2}">→</a>
</li>
<li th:class="${ads.number + 1 == ads.totalPages} ? disabled">
<a class="pageLink" th:href="${ads.totalPages}">»</a>
</li>
</ul>
</div>
</div>
In this case, you should be using thymeleaf's built in url syntax. It would look like this:
th:href="#{/{page}(page=${page})}"
Creating a link with #{/} means that thymeleaf automatically adds the context (Phoenix-listings in your case.) {page} is a placeholder. (page=${page}) replaces the placeholder with the variable.
You can also use string concatenation, but I wouldn't recommend it in most cases (because using the standard syntax means thymeleaf can correctly encode urls).
th:href="#{${'/' + page}}"

Why if I add the id attribute to span inside bootstrap navbar the JSP/Tiles exceptions aren't shown?

I found a weird problem in my project. I'm using Spring MVC, Tiles, JSPX and Boostrap.
I have a navbar in my header page, then I added a span to show a badge like https://getbootstrap.com/docs/3.3/components/#badges.
Till here nothing strange. But If I add an id on span tag and there is an error inside the html code, I can't see any log or exception.
Here the code
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<span class="fa fa-male"><jsp:text/></span>
<span class="badge badgeNavbar" id="badgesContrattiDaApprovare">
<jsp:text/>
</span> ${clienti}
<span class="caret"><jsp:text/></span>
</a>
<ul class="dropdown-menu">
...
</ul>
Instead If I remove id="badgesContrattiDaApprovare" I can see the exceptions.
Are there any conflicts between span and id?
SO: Why if I add the id attribute to the span inside bootstrap navbar the JSP/Tiles exceptions aren't shown inside the rendered view?
For example here if an exception occurs without the id attribute:
Instead, if I add the id attribute is like the rendering is stopped, and I see only a blank page. The generated/rendered html code is incomplete.

Ruby/Watir select a choice from a drop down menu

Hello I am relatively new to QA automated web testing and I try to use SO as a last resort.
That being said I am having issues selecting a choice from a drop down menu in our web app.
Here is the following code:
<div id="edit-main-user-role-wrapper" class="form-item">
<select id="edit-main-user-role" class="form-select my-dropdown ahah-processed" name="main[user_role]" style="display: none;"></select>
<div class="newListSelected" style="position: static;">
<span class="selectedTxt">
Student
</span>
<ul class="newList" style="top: -136px; height: 136px; left: 0px; display: none;">
<li>
<a class="" href="JavaScript:void(0);"></a>
</li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</div>
When I inspect the drop down icon with Firefox inspect element it directs me to this line in the code: span class="selectedTxt"
I have tried accessing the list by id, class, xpath, and css all to no avail.
Here are some of my past attempts:
#browser.div(:class => 'form-item').select_list(:text => 'Student').fire_event ("on click")
#browser.select_list(:xpath, menu).option(:text, option).click
An element with a select tag should only be meaningful if there are elements with option tags nested inside it. Often these pages have a lot of extra javascript in them to give context.
For dropdowns that don't follow the select/option pattern, you want to click on the element that drops down the list, and then click on the element you want that becomes visible as a result.
This is what eventually worked for me:
#browser.span(:class, "selectedTxt").click # to make the list visible
#browser.element(:xpath, "#{xpath}").click # click on the specified xpath
I know this may not be the most elegant answer, but it works!
not sure if you're still looking for answers, but either of these worked for me:
#browser.select_list(:id => "you_leaving_us").option(:text => "Other").select
#browser.select_list(:id => "you_leaving_us").option(:value => "8").select
Instead of li's, I had options. Hope it works

jQuery - who is blocking my events?

I'm using the mmenu plugin on a page that's based on jquery-mobile. Mmenu gives me left and right sliders which work fine except for when I try to open a 'mobile-style' popup window. These messages / events aren't getting out.
I have other popup windows on this page so I know that the popup code works but when I try to use the same code inside the <li><a href="#popup" ... ></a></li> framework for mmenu it does nothing.
Chrome script debugger doesn't show any errors. The styles and markup are the same between the working and non-working buttons (when viewed in the debugger).
popup window
<div data-role="popup" id="optionsDialog" data-overlay-theme="a" data-theme="b"
data-dismissible="false" style="max-width:400px;" >
<div data-role="header" data-theme="a">
<h1>Options</h1>
</div>
<div role="main" class="ui-content">
Some options go here?<br>
<a href="#" class="ui-btn ui-corner-all ui-shadow ui-btn-inline
ui-btn-b" data-rel="back">
Cancel
</a>
</div>
</div>
button to open popup
<a href="#optionsDialog" id="options_button" data-role="button"
data-mini="true" data-rel="popup" data-position-to="window"
data-transition="pop">
Show popup
</a>
How do I go about finding my missing events?
FWIW: No idea what mmenu is doing to stifle this event but it was solved by scripting as follows:
$( "#options_button" ).click( function()
{
$( "#optionsDialog" ).popup( "open", {} );
});
...
<li><a href="#" id="options_button" >Options</a></li>
plain old jQuery.

Resources