Need help to click Watir Web driver button - watir-webdriver

I have the HTML as
<li>
<div data-track="discovered_spots" data-filter="discovered_spots" class="button filter-button">
<span class="icon-compass"></span>
Discoveries (2)
</div>
</li>
I am trying to click the button link
#browser.div(:class =>'button filter-button').span(:text => ' Discoveries (2) ').click
Just not working or producing any errors.
I have also tried using the xpath
##browser.div(:xapth => "//div[#data-track='discovered_spots']").click
##browser.div(:text => "Discoveries").click
but that produce errors.
I have also viewed and tried the code present in other questions chains but none worked any help will be very useful.

Try:
#browser.div(:text, /Discoveries/).click
Regex for the attribute should hit the text. Not specifying \d anchor will cast a wider net in case that value of 2 fluctuates by only looking for the match of Discoveries in text and ignoring the number and parentheses.

Related

Get inner most regex match for a href regex catcher

I want to catch href tags with a youtube link inside them.
I have this regex:
"<a.*?href=(.*?youtu.?be.*?)>.*?</a>"
It works but it doesn't stop if the tag is closed.
Meaning if I have:
<a href=www.google.come>google</a> <a href=www.youtube.com>youtube</a>
Desired result:
<a href=www.youtube.com>youtube</a
Actual result:
<a href=www.google.come>google</a> <a href=www.youtube.com>youtube</a>
It catches the whole thing, recognizing Googles <a as the opener and youtubes </a> as the closer.
I want to make my regex a little smarter so it knows how to stop the match when the the Google closer appeared, and start a new match attempt when the Youtube opener appears.
I tried this but it didn't work:
"<a.*?[^>]href=(.*?youtu.?be.*?)>.*?</a>"
And also tried this:
"<a[^>].*?href=(.*?youtu.?be.*?)>.*?</a>"
You can try this pattern :
"<a[^>]*?href=[^>]*?youtu.?be[^>]*?>[^>]*?<\/a>"

Typical issue: css Element not found

I have a typical problem with selenium Ide: [error] = * css Element not found.
I looked in the forum and I have seen very similar questions (eg, selenium-IDE-2.9.0 - [error] = li.xspPickerItem.xspPickerItemHover css Element not found), have tried to solve the problem with some of the suggested answers but I could not.
The details of my problem is as follows:
Log:
info] Executing: |click | css=input.select-dropdown.active | |
[error] Element css=input.select-dropdown.active not found
[info] Test case failed
HTML
(it contains several drop-down lists):
<div class="row" _ngcontent-pkb-13="">
<div class="col s2" _ngcontent-pkb-13="">
<label for="groupBy" _ngcontent-pkb-13="">Agrupado por</label>
</div> <div class="col s5" _ngcontent-pkb-13="">
<div class="select-wrapper form-control ng-untouched ng-pristine ng-valid initialized">
<span class="caret">/span>
<input class="select-dropdown" readonly="true" data-activates="select- options-32184002-bd89-baf2-43b8-3d88ae8219e5" value="Todo el territorio" type="text"></input>
<ul id="select-options-32184002-bd89-baf2-43b8-3d88ae8219e5" class="dropdown-content select-dropdown ">
<li class=""><span>Todo el territorio</span></li><li class=""><span>Instalaciones Deportivas</span></li><li class=""><span>Parroquias</span></li><li class=""><span>Polígonos Industriales</span>
(it shows a small part)
How you could select any item from the drop down ?, eg. "Parroquias"
Thanks
From the code you've posted you don't need the '.active' on the end of the locator, it should just be 'css=input.select-dropdown' However if you have multiple dropdowns this may not be the most efficient way of targetting them if they'd all have the same class. If you have control over the code you may want to add id's onto the dropdowns and use that for your target
As for getting it working, I can't get a working example on my machine as for it to appear as a dropdown you'd need your css, as you've coded it to just be a list but the css formats it as a dropdown, rather than using the 'select' tag. Normally you'd use the 'Select' command in Selenium, targetted at the dropdown, rather than a click command but I'm not sure if it would work with the way this page is coded as I've not come accross it before (my instinct would be no) so it probably would be the click on the dropdown as you're trying, then a click on the specific list item.

Finding font-weight value for span[2] element in Selenium IDE

Is there a way to verify that element 'Adam Slodowy' is bold in Selenium IDE?
This is the fragment of site code:
...
<div class='thread-content-row.thread-content-row-1'>
<div class='thread-content-row-left'>
<div class='thread-content-row-right'>
<div class='discussion-info'>
<b>Daria Ogrodowska</b>
do
<span>super</span>
,
<span>Adam Slodowy</span>
</div>
<div class="discussion-content"> bla bl balkjbasdfsdfsdfdsfsdf sdfsdf sdf sdf </div>
</div>
</div>
I've tried to use verifyEval command:
Command: verifyEval
Target: var elem = window.document.querySelector("div.thread-content-row.thread-content-row-1 > div.thread-content-row-right > div.discussion-info span"); window.getComputedStyle(elem,null).getPropertyValue("font-weight");
Value: 700
but I have no idea how in querySelector refer to second span - querySelector("div.thread-content-row.thread-content-row-1 > div.thread-content-row-right > div.discussion-info span[2]") doesn't work.
It is really much more practical for a human person to check styles as even if it was bold it could look really bad and Selenium wouldn't be able to tell if it looked "bad" or not.
That being said, you would probably want to utilize xpath query on this one.
xpath=//span[contains(text(), 'Adam Slodowy')
or if you have more than one of those in your web page.
xpath=//div[#class='discussion-info']/span[contains(text(), 'Adam Slodowy')
the // indicates to look through the web page for an element that matches whatever follows. Which is very beneficial so that you don't have to include entire xpath which is very fragile if any of the structure changes.

Why does the first assert work, but not the second?

I'm using Watir WebDriver with Firefox.
Here are two asserts for the same element. The first works, but not the second:
assert_match(/Please add user to GMT/, #browser.small(:class, "error").text)
assert_match(/Please add user to GMT/, #browser.div(:class, "eight mobile-three columns").small(:class, "error").text)
I need the second assert to work, because there are 8 error messages on the page, which are presented if the user does not populate 8 mandatory fields. All 8 errors have the identical HTML. So, I need to be able to step down from the parent.
Here is the HTML:
<div class="eight mobile-three columns">
<a id="btnAddUserToGMT" class="success radius button expand error" onclick="AddUserToGMT();" data-reveal-id="addToGMT" href="#"> … </a>
<small class="error" style="margin-top:0px;">
Please add user to GMT
</small>
</div>
Here is the error message:
Watir::Exception::UnknownObjectException: unable to locate element, using {:class=>"error", :tag_name=>"small"}
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.4/lib/watir-webdriver/elements/element.rb:490:in `assert_exists'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.4/lib/watir-webdriver/elements/element.rb:85:in `text'
C:/Documents and Settings/Asserts_01.rb:22:in `testBasic'
The complaint for the second assert is:
unable to locate element, using {:class=>"error", :tag_name=>"small"}
And yet that same using was OK for the first assert.
Problem solved.
After discussion with the developer, it appears that by some unusual manipulation of automatically generated HTML, the text of the error message appears at its correct location on the page. But the assertion must be based on a different tag, which is specified at some completely different position on the page.
For example, I was trying to assert on this code at the correct position:
<small class="error" style="margin-top:0px;">
Gender is required
</small
Even unique xPath generated by FirePath failed to find this.
What I should have asserted on was a HIDDEN tag on a completely different part of the page.
<input id="errorMsgGenderID" name="errorMsgGenderID" type="hidden" value="Gender is required" />
There were several such tags for each mandatory field that was not populated, all bunched together on the same line. They were all "input" tags, which puzzled me.

jquery .html() returning null in ie7

On click li element i am getting the current element value and appending it into another div dynamically.Its working fine in all browsers.But returning null in IE7.I don`t the reason that why its happening?Please can any one give me a solution for this..Part of the code only i pasted here.
Sample code:
////////////.//This line returning null in IE7./////////////////
$('#pagelink_a #pagelinkli_'+tab_lastid_val).html()
(tab_lastid_val value can be a 1 or 2 or 3.Clixked li element value comes here)
<div class="pagelink">
<div id="pagelink_a">
<ul>
/******** all li element are clickable***********/
<li id="pagelinkli_1"><a>Google</a></li>
<li id="pagelinkli_2"><a>Chrome</a></li>
<li id="pagelinkli_3"><a>Firefox</a></li>
</ul>
</div>
</div?
try this:
$('#pagelink_a').find('li[id=pagelinkli_'+tab_lastid_val']').html();
code is not tested but i think it should work.
Given your html layout, your parent div is .pagelink not #pagelink_a , so replace your following line:
$('#pagelink_a #pagelinkli_'+tab_lastid_val).html()
for this one:
$('.pagelink #pagelinkli_'+tab_lastid_val).html()
Just use
$('#pagelinkli_'+tab_lastid_val).html()
The # tag identifies an ID which only a single element may have. There is no need to have anything preceding it. You also labeled the previous class as id, which is wrong. I don't know how your other browsers managed to get anything.
Although bit off topic, it may be better to actually drop IE7 support entirely. Due to small user base and decreasing popularity, it may be costing you more money by support it than to not support it.
Try instead of html() , and try append().
For example
$('#ID').append('Your content');