Trouble using Watir to click a tab on a page - ruby

I am trying to click the second tab Tab1_imgImbillsTab.
<div id="menuTabsForPageContainer" >
<div id="menuTabsForPage">
<img id="Tab1_imgHomePageTab" accesskey="H" disabled="disabled" class="imgHomePageTab" src="images/home_deselected_tab.png" alt="Home" style="border-width:0px;" />
<img id="Tab1_imgImbillsTab" accesskey="B" class="imgImbillsTab" src="images/bills_deselected_tab.png" alt="Bills" style="border-width:0px;" />
<img id="Tab1_imgArchiveTab" accesskey="C" class="imgArchiveTab" src="images/chartrack_deselected_tab.png" alt="Chart Rack" style="border-width:0px;" />
<img id="Tab1_imgPracMgmtTab" accesskey="I" class="imgPracMgmtTab" src="images/managementreporting_deselected_tab.png" alt="Business Intelligence" style="border-width:0px;" />
<img id="Tab1_imgSysToolTab" accesskey="Y" class="imgSysToolTab" src="images/systemtools_deselected_tab.png" alt="System Tools" style="border-width:0px;" />
<img id="Tab1_imgBulletinTab" accesskey="S" class="imgBulletinTab" src="images/settings_deselected_tab.png" alt="Settings" style="border-width:0px;" />
</div>
</div>
I tried several things:
browser.button(:id => 'Tab1_imgImbillsTab').click
browser.div(:id, "menuTabsForPage").div(:id, "menuTabsForPage").button(:id, "Tab1_imgImbillsTab").click
I also tried to reference it as a clickable image by referencing the "src" of the image. These tabs, I believe have JavaSceript behind them. I can not figure out what I'm doing wrong.

The code:
browser.button(:id => 'Tab1_imgImbillsTab').click
Says to find a button element or input element (of type button, reset, submit or image) that has the id "Tab1_imgImbillsTab".
However, based on the HTML, the tab is an img tag. As a result, it will never be found by the button method. Tell Watir to look for the img tag instead:
browser.img(:id => 'Tab1_imgImbillsTab').click

Related

Issue with clicking on a button

I have a save button on my window whose html is
<div class="popup supportsLink editor">
<h2></h2>
<a class="close icon small" href="#"></a>
<style></style>
<form method="post" enctype="multipart/form-data" action="/AirWatch/Blob/upload-blobs" data-name="blobform">
<div class="editor"></div>
<div class="footer">
<div class="actions" align="center">
<input type="submit" value="Save"></input>
<input type="button" value="Cancel" onclick="closeClosestTray($(this));"></input>
I am not able to click on the save button. when i do an exists? in irb i get a true value. Can someone help me with this.
I am still new to Watir and still am getting my bearings but maybe
browser.form(:value=>'Save').submit
If that doesn't work, is the button in a pop up? if so did you account for this?
so maybe something like this:
browser.window(:title => "annoying popup").use do
browser.button(:id => "close").click
end
What error do you get when you try clicking?
I made a page with your provided html and made script for clicking that and that normal code works for me, and it clicked that button and no error, I used:
browser.button(value: 'Save').click

Magento - newsletter pop code using ajax update in form

I have the below code that is being used in cms page pop up
the problem im having is if you leave email address input field blank and hit the submit (in the case "Get Code" button, you briefly see the red validation message but then hides the form, shows the hidden div.
why or how can I prevent this process, i want it to validate but proceed to show the hidden div content. Below is the code.
<div id="pop-confirm" style="display: none;">
<h1 style="color: #000000; font-weight: bold;">THANKS!</h1>
<p> </p>
<h2>Use code: <strong>extra15</strong><br /> for 15% off your purchase.</h2>
</div>
<form id="newsletter-validate-detail" action="home/send" method="post" onSubmit="new Ajax.Updater({success:'newsletter-validate-detail'}, 'newsletter/subscriber/new', {asynchronous:true, evalScripts:false, onComplete:function(request, json){Element.hide('newsletter-validate-detail');Element.show('pop-confirm');}, onLoading:function(request, json){}, parameters:Form.serialize(this)}); return false;">
<div class="block-content">
<h2>ENTER YOUR EMAIL<br /> AND GET</h2>
<div class="form-subscribe-header">
<h1>15% OFF</h1>
<br />
<h1>EVERYTHING!</h1>
</div>
<div class="input-box"><input id="newsletter" class="input-text required-entry validate-email" title="Sign up for our newsletter" type="text" name="email" /></div>
<br />
<div class="actions"><button class="button" title="Get Code" type="submit"><span><span>Get Code</span></span></button></div>
<br />
<p><em>* Promotion ends April 6th</em></p>
</div>
</form>
<script type="text/javascript">// <![CDATA[
var newsletterSubscriberFormDetail = new VarienForm('newsletter-validate-detail');
// ]]></script>
Im very new to ajax so maybe ive done something wrong.
any ideas or suggestion would be greatly appreciated.
Thanks
Try changing your onSubmit to the following:
onSubmit="if(newsletterSubscriberFormDetail.validator.validate()){ new Ajax.Updater({success:'newsletter-validate-detail'}, 'newsletter/subscriber/new', {asynchronous:true, evalScripts:false, onComplete:function(request, json){Element.hide('newsletter-validate-detail');Element.show('pop-confirm');}, onLoading:function(request, json){}, parameters:Form.serialize(this)}); } return false;"`
This wil trigger the validator before submitting the form with AJAX. Works perfect for me :)

How to stop auto-refresh onclick from thumbnails?

I have an image gallery on my site that uses thumbnails that enlarge above the thumbnail line when clicked on. I'm having an issue with the auto-refresh; every time I click one of the thumbnails, the page refreshes, which restores it to the "master image".
I'm not (and sort of refuse, on the grounds that I believe all this can be done with simple CSS and HTML) using anything fancy to write this code, despite my knowledge of HTML being amateur at best.
Here's a sample of the code. Let me know if you need to see a different piece of it.
<div id="rightcol">
<img name="ImageOnly. src='#' /><img src="#" />
</div>
<div id="leftcol"> <div>
<a href="" onclick="ImageOnly.src='#'"><img src="#" />
</div>
Edit: Somehow I seem to have fixed this issue by changing
<a href="" onclick="ImageOnly.src='#'">
to
<a href="#" onclick="ImageOnly.src='#'">
Not really sure why this worked but would love an explanation...?
Why not just use some simple ajax/javascript .innerHTML? instead of trying to stop the auto refresh that occurs when you click on a hyperlink that has #. That way you could update the rightcol synchroniously.
HTML
<div id="rightcol">
<img name="ImageOnly.src" src='#' />
</div>
<div id="leftcol">
<img src="#" />
</div>
AJAX Script
function ajaxMove(src)
{
var image = '<img src="'+src+'" alt="my transferred image" />';
document.getElementById('rightcol').innerHTML = image;
}
How is it used?
Request the object from the onclick event.
Build an image tag based off the information in the object.
Transfer the new image tag to the element with the id 'rightcol'
Other options
You could also remove the href="#" from the <a> tag and work directly from the onclick event and then apply style="cursor:pointer;". Then it will work like a regular hyperlink but without the refresh.
<a onclick="javascript:ajaxMove('ImageOnly.src')" style="cursor:pointer;" >Click Me</a>

Easier way to click button in nested divs with Watir?

I'm new to Watir and I'm trying to click the following login button:
<div class="container login" style="display: table;">
<div class="left">
<div class="right">
<div class="joinbox">
<form id="form_login" class="hidden-submit" method="post">
<input type="submit" value="Submit">
<div class="header">
<div class="left">
<div class="mid">
<div class="right">
<a class="button button-red submit" href="#">Log In</a>
...
So far I'm able to access this button by going through every nested div:
b.div(:class, "container login").div(:class, "right").div(:class, "joinbox")......
and so on. Is this really the best way to access this button? I assume I'm missing something. Any help is appreciated!
If there is only one link (that looks like a button) with text Log In on the page, try this:
browser.a(:text => "Log In").click
You could also use class attribute:
browser.a(:class => "button button-red submit").click
May this work?
browser.form(id,form_login).submit
BTW: I have seen some tips said safari only support GET mode for submit.
I would try:
browser.a(:href => "#").click
Assumption - "#" is unique. may need a slash so it doesn't misinterpret the #. I used something similar when I was trying to reference a button with only a href value of "/login" e.g., browser.a(:href => "/login").click.

HTML source indentation for ckeditor

When you add some code to a ckeditor in HTML view and then change to WYSIWYG view and come back, almost all HTML tags have been modified and have loose the indentation. Is there any way to prevent this behaviour? (parameter, plugin, hard code...)
For example:
<div class="former input">
<span class="big horizontal">
<label for="test">Hi world</label>
<input class="medium free" id="test" name="test" type="text" />
</span>
</div>
Becomes:
<div class="former input">
<span class="big horizontal"><label for="test">Hi world</label><input class="medium free" id="test" name="test" type="text" /></span></div>
Here's a link to a page in the developer's guide:
Output Formatting
It explains how to control the layout of the HTML code that is output by the editor and has an example that sets the formatting for the <p> tag.
Try using the <p> tag example as a template and set the formatting for the <span>, <label> and <input> tags using the same approach.
writer.setRules( 'span',
writer.setRules( 'label',
writer.setRules( 'input',
Be Well,
Joe

Resources