I have a simple assertion on a disabled button within my selenium test that fails. The method expects the button to be disabled but when I run the test it fails stating that the button is actually enabled.
I use Ruby/Rspec and this is the code used to check that button is disabled. I've removed the references to the class and page object but the button object locator used is by :id.
expect(Page.btn.enabled?).to be false
Here is the html of the page for the disabled button I am testing:
<input type="submit" name="ctl00$bodyContentPlaceHolder$btnContinueToAddress" value="Next" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$bodyContentPlaceHolder$btnContinueToAddress", "", true, "", "", false, false))" id="ctl00_bodyContentPlaceHolder_btnContinueToAddress" class="btn btn-primary btn-block disabledContent">
I would expect the selenium test to pass as the button IS disabled on the page, but the rspec results show:
expected false
got true
Is the locator used incorrect and the :id is actually enabled? Is there something I'm missing? Thanks in advance.
Related
I am automating a test on a page and I need to click the "Add images" button. But it's not reacting
<button class="btn btn-default awe-hidden" id="html5button" onclick="$('#html5files').click();return false;">Add images</button>
I have tried
cy.get('button').contains('Add images').click()
cy.get('button').contains('Add images').invoke('show').click()
cy.get('button').contains('Add images').invoke('show').click({force: true})
cy.get('button').contains('Add images').trigger('mouseover').dblclick()
Also tried trigger 'mousedown', short wait then 'mouseup'
Also tried cy.contains('Add images').click()
Any ideas?
The onclick() event handler contains a jQuery expression, but I suspect Cypress doesn't handle it properly.
You can use cypress-real-events instead
cy.get('button').realClick()
Unable to click on OK button
I tried like this but it is not clicking.
b.find_element(name: "OK").click #----> it is not clicking
How to interact with this type of pop-us in ruby.
<input class="copybutton" type="button" title="Copy" onclick="copyErrText()" name="copy" value=""/>
<!-- *** Added: copy button *** -->
<button class="button" onclick="disp()" name="OK" value="OK" type="button">OK</button>
You can try one of the following it may help you.
ele = find_element(name: "OK")
driver.action.move_to(ele).click(ele).perform
or
driver.execute_script("arguments[0].click();",ele)
or
driver.execute_script("disp();")
You've tagged this Watir, but your syntax is Selenium. If you are using Watir, it would look like this:
browser.button(name: 'OK').click
If there are funky javascript things going on, you can fire an event to interact with it. Use this power sparingly.
browser.button(name: 'OK').fire_event :click
Hope this helps.
driver.switch_to.alert.accept
So I have been experimenting with Watir automation scripts using Ruby. I have tried to experiment with different websites, like Twitter, Gmail, and Yahoo. Here is the catch: I am able to open a browser, login, and get to the home page. On all of these whether it is compose a new email or tweet every time I select it with the appropriate ID or Class, it throws an error in the terminal like this...
.rvm/gems/ruby-2.2.1/gems/watir-webdriver-0.8.0/lib/watir-webdriver/elements/element.rb:533:in assert_element_found': unable to locate element, using {:title=>"compose", :tag_name=>"button"} (Watir::Exception::UnknownObjectException)
from /Users/xxx/.rvm/gems/ruby-2.2.1/gems/watir-webdriver-0.8.0/lib/watir-webdriver/elements/element.rb:505:inassert_exists'
from /Users/xxx/.rvm/gems/ruby-2.2.1/gems/watir-webdriver-0.8.0/lib/watir-webdriver/elements/element.rb:114:in click'
from yahoo_mail.rb:18:incompose_email'
from yahoo_mail.rb:27:in `'
My question is, are there elements that you simply cannot click or select using Watir automation?
EDIT: How would I be able to hit this to be more specific? I seem to be getting the same results on Yahoo, Gmail, and Twitter when it comes to composing anything after getting logged in. So I how would I hit this button?
button id="global-new-tweet-button" type="button" class="js-global-new-tweet js-tooltip btn primary-btn tweet-btn js-dynamic-tooltip" data-placement="bottom" data-component-term="new_tweet_button">
The HTML for the Compose button is basically the following (NOTE: id attribute removed):
<button tabindex="0" data-action="compose" title="Compose" class="btn btn-compose">
Your stacktrace indicates that you're using this locator:
{:title=>"compose", :tag_name=>"button"}
If you change :title=>"compose" to :title=>"Compose", you should be in business.
Have you tried the following code?
button(id:'global-new-tweet-button').when_present.click
Maybe you were clicking the button without checking if it is already present on the page.
During a page's "dormant" state, I can inspect the values of any tag by entering its id in Chrome Dev Tools' console tab, like so, e.g. for a tag with the name "BeginDate":
0) Enter "BeginDate" in the console tab
1) Mash the key
...and I see the whole shebang:
<input alt="date-us" data-val="true" data-val-regex="End Date must be in the format "m/d/yyyy"" data-val-regex-pattern="[0-9]*[0-9]/[0-9]*[0-9]/[0-9]{4}" data-val-required="End Date must be in the format "m/d/yyyy"" id="EndDate" name="EndDate" style="width: 164px;" type="text" value="5/14/2013" class="hasDatepicker">
So it shows the value, which is the part I'm interested in, is today's date.
What I want to inspect, though, is just what is being passed/posted when the form's Submit button is pressed; I believe this would be, in asp.net, the contents of the Request object, but how can I see these vals using Chrome Dev Tools?
I right-clicked in the console and selected "Log XMLHTTPRequests" and "Preserve log upon navigation" but...are they logged? If so, where are they? I see nothing in the Console tab...
UPDATE
Thanks to David Ziemann, here's what I see:
The Network tab will show you any network communication. Within that you can select the request and view the headers which should include the form data.
So I have a method that implements IHttpHandler.ProcessRequest. It accepts an HttpContext parameter. This parameter is just a form that is filled out with some XML. Here is the HTML that I am using to generate the post context:
<html>
<body>
<form name="form1" method="post" action="http://localhost:7703/api.ashx">
<textarea name="XML" id="XML" rows="25" cols="100"></textarea>
<br/>
<input type="submit" value="submit"/>
</form>
</body>
</html>
As you can see, very simple. This is just used for testing purposes. What I am doing is posting XML in that textbox, and hitting submit. However, I am not sure what to attach my visual studio project to in order to debug. I try attaching it to w3wp.exe like I do when I test the app in a browser and stuff, but that doesn't seem to be working. It still says "This breakpoint will never be hit, no symbols loaded..." blah blah blah, when I put a breakpoint next to the ProcessRequest method and attach.
How do I test this properly?
Thanks guys.
If you run this locally you should be able to "run" it from within Visual Studio and VS will automatically attach it self to the correct process.
If I attach to the development server at the same port as the post, it works! :)