Watir Click_no_wait clicking too fast? - watir

I have used click_no_wait to click a button and then used javascript_dialog.button('OK').click to click the "OK" button on the resulting pop up. This has worked in all situations except for one for me. It appears the click_no_wait is clicking too fast.
By this I mean that when I use click_no_wait the button on the page flashes (as if clicked) but the pop up does not occur, and then my Watir app hangs, waiting for the pop up which does not pop up. If I switch to click then the pop up occurs, but the Watir app hangs (as would be expected).
Is there another option available? The code is below. (I cannot link the actual site, it is behind a passworded area)
Ruby / Watir:
browser.button(:name => "dgPermission:_ctl"+num+":_ctl1").click_no_wait
browser.javascript_dialog.button('OK').click
HTML:
<html><body><div><table style="width:100%; height:600px;"><tr>
<td>Group Name</td>
<td><span disabled="disabled"><input id="dgPermission__ctl2_cbAdd" type="checkbox" name="dgPermission:_ctl2:cbAdd" checked="checked" disabled="disabled" /></span></td>
<td><input type="submit" name="dgPermission:_ctl2:_ctl0" value="Edit" /></td>
<td><input type="submit" name="dgPermission:_ctl2:_ctl1" value="Delete" onclick="javascript:if (!confirm('Are you sure you want to remove this permission?')) return false;" language="javascript" /></td>
</tr></table></div></body></html>
(The page can contain multiple groups, so the middle section could have multiples of that section, each with a different number ID in the dgPermission name)

as far as I know the only difference between click and click_no_wait is what happens after the click is sent.
potentially you could try firing off the event directly
browser.button(:name => "dgPermission:_ctl"+num+":_ctl1").fire_event('onclick')
browser.javascript_dialog.button('OK').click

Related

How to fix Talkback announcing checked state change multiple times when changing radio button selection on Google Chrome for Android

I'm working on a AA accessible web application where I have a simple form with radio button group. When I have already selected a radio button and change the selection, Android Talkback announces state changes twice.
It would say, "unchecked checked" or "checked unchecked".
My markup is strictly following the accessibility guidelines as described here https://webaim.org/techniques/forms/controls#radio. I'm not even sure if this is a bug or feature.
Codepen: https://codepen.io/bhargavshah/pen/PXVBML
<fieldset>
<legend>Choose a shipping method:</legend>
<input id="overnight" type="radio" name="shipping" value="overnight">
<label for="overnight">Overnight</label><br>
<input id="twoday" type="radio" name="shipping" value="twoday">
<label for="twoday">Two day</label><br>
<input id="ground" type="radio" name="shipping" value="ground">
<label for="ground">Ground</label>
</fieldset>
Expected Result: Talkback should just announce "Checked" on a radio button when selection changes.
Actual Result: Talkback announces "Unchecked checked" on a radio button when selection changes.
I just came across this post as I was looking for an answer to a different question related to checkboxes, but just in case you never got your answer, this is not a defect. This is expected screen reader behavior to tell you the current state of the item followed by the new state.

How can I submit a form to a new tab in my chrome extension

I am working on a Google chrome extension. the idea is that I enter my username and password, click submit and have a new tab open with my website, which will then pick up the submitted form and log me in.
I have managed to open my website in a new tab, but can not get it to pick up the form.
You can use OnClick event in submit button:
<input type="submit" value="submit" onclick="this.form.target='_blank';return true;">
You can create an HTML form in your popup.html as follows:
<form name="input" action="http://example.com/login.php" method="get">
Username: <input type="text" name="user">
Password: <input type="password" name="password">
<input type="submit" value="Submit"></form>
And in the script of your website you can check if the parameters and have been passed, and if correct then create redirect them to the DashBoard on your site, otherwise show them the login page to enter the correct credentials
Since you've got your website loaded, try using jquery to select the textbox and enter a value.
The following selects the where the input is, then finds the input I want, then finally sets the value inside of that box.
$("td[data-key='sku']").find("input.tb-input").val('some text here')
In the jquery code above, the html would look something like this:
<td data-key='sku'>
<input class=tb-input/>
</td>

Read-only text field

I have an read-only text-field in my site. And I need to enter a date using cucumber and watir. But I can't set any value. Even passing the value of date with value = method I can't input any output. There is a JavaScript calendar.
I wrote:
browser.text_field(:name => "deal[start_date]").value = 'test'
it shows the following error:
Watir::Exception::ObjectReadOnlyException: Watir::Exception::ObjectReadOnlyException
from /var/lib/gems/1.8/gems/watir-webdriver-0.1.7/lib/watir-webdriver/elements/element.rb:252:in `assert_writable'
from /var/lib/gems/1.8/gems/watir-webdriver-0.1.7/lib/watir-webdriver/elements/text_field.rb:24:in `value='
from (irb):10
Please help me, I am in a trouble.
This goes along with what xboxer21 noted. I found this code worked for me on a site that had a similar calendar widget.
Lets say you have an HTML form with input text fields that are set to readonly:
<form name="FindRange" method="post" action="FindRange.asp" onsubmit="return false">
...
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="3" class="FieldLabel">
<input type="text" name="FromDate" size="16" readonly="true" style="width:85px; background-color:#F8F6E7;">
</td>
<td>
<input type="text" name="ToDate" size="16" readonly="true" style="width:85px; background-color:#F8F6E7;">
</td>
</tr>
...
</form>
Using code like '#ie.text(:name, "FromDate").set("3/23/2011")' in your Ruby Watir script would result in an error in Ruby stating the field was read-only. But using the eval() method may allow you to use Javascript to set the read-only fields behind the scenes.
#Code above these lines instantiate the Watir object in #ie and navigate to the page #containing the HTML form
#named 'FindRange'
#ie.document.parentWindow.eval("document.FindRange.FromDate.value = '3/23/2011'")
#ie.document.parentWindow.eval("document.FindRange.ToDate.value = '3/24/2011'")
Well, the text field is read only, as the error message says. That means it can not be changed. How would you change the value of the text field without Watir? Can you provide link to the page or relevant HTML?
This is what I did to enter a date in a read only text field, The JS calendar script used was http://www.dynarch.com/projects/calendar/
There is a small icon next to the date field which displays the calendar widget upon clicking it.
browser.image(:id,"datewidget-trigger").click # Will display the Calendar
browser.send_keys("{ENTER}") # Will select current date
If you want to select a future date or previous date
browser.send_keys("{LEFT}")
browser.send_keys("{RIGHT}")
This has been tested using IE only.
Try executing the JavaScript itself.
browser.document.parentWindow.execScript("Date_JS_script('date')")

Capybara not finding submit button by name

I have some weirdness occurring while trying to switch from webrat to capybara. The error is this:
And I press "Create floob"
# features/step_definitions/web_steps.rb:27
no button with value or id or text 'Create floob' found (Capybara::ElementNotFound)
The html in my app looks like this:
<fieldset class="buttons">
<ol>
<input id="floob_submit" name="commit" type="submit" value="Create floob" />
</ol>
</fieldset>
I would have thought that capybara would look at the value of the buttons on the page, and reading the documentation this does seem to be the case, but it's not working! If I change the line in my cuke file to And I press "floob_submit" everything works, but I'd rather not change all my features...
Does anyone have any thoughts on why this might be happening and if there's a fix? Thanks friends!
The only thing I can see is that you aren't wrapping your input in an <li></li>. This might be confusing enough for the DOM to cause your problem.

ModalPopupExtender closing as soon as it opens

I'm trying to use the AjaxToolkit's ModalPopupExtender, but it doesn't work. In fact, as soon as it opens, it's getting closed. So I can see that it is rendered, but it's getting closed in the second.
I tried that with IE6 and Firefox 3, it does the samething.
Here's the code:
<AjaxControlToolkit:ModalPopupExtender ID="ModalPopupExtender1" TargetControlID="ButtonTarget" PopupControlID="Panel1" OkControlID="ButtonOk" CancelControlID="ButtonCancel" BackgroundCssClass="modal-background" runat="server">
</AjaxControlToolkit:ModalPopupExtender>
<asp:Panel ID="Panel1" Style="display: none;" runat="server">
<%-- some stuff... --%>
</asp:Panel>
Use update panel for that work because when you click button it take also post back so thats why you just see the popup and it close on same time.

Resources