NightWatch - unable to find element with xpath locator on an input with value - node.js

With nightwatch, I have issues to find an element on my page, The XPATH is GOOD, because I a have find it with FirePath.
My page code :
<label class="switch " data-ng-repeat="item in values">
<input class="ng-pristine ng-untouched ng-invalid ng-invalid-required"
name="obtentionPermisConduiteAccompagneeSwitcher" value="N" ng-
model="$parent.model" ng-required="!$parent.model" required="required"
type="radio"/>
......
My selector:
input_conduiteAccompagnee: {
selector: './/input[#name="obtentionPermisConduiteAccompagneeSwitcher" and #value="N"]',
locateStrategy: 'xpath'
},
My command :
//conduite accompagnee
onglet_conducteur.waitForElementVisible('#input_conduiteAccompagnee',
10000);
onglet_conducteur.click('#input_conduiteAccompagnee');
browser.pause(3000);
But I have the message :
× Timed out while waiting for element to be visible for 10000 milliseconds. - expec
ted "visible" but got: "not visible"
Have you already have the same issue ?

# Ratnadip,
It return 1 element by XPATH.
But I think you have right concerning the scrolling because my element is lower in the page..
I tried some thinks like :
onglet_conducteur.getLocationInView('#select_conduiteAccompagnee',
function(result) {
this.execute('scrollTo(result.value.x, result.value.y)');
this.execute('scrollIntoView');
});
but it does not work.
Thanks

Related

Can't click on button from Selenium

I am trying to click on any one of the three buttons below but can not find a name, ID or class the identify the
Any hints?
<user-tile-actions ng-transclude="actions"> <!----><button ng-if="!vm.user.isBlockingMe
&& !vm.user.isBlocked" type="button" class="button-height-32 button-padding-10 follow-icon
button-scs button-scs-shadow" user-follow="vm.user" event-label="user-tile-small"><i class="icon-
person-plus"></i></button><!----> </user-tile-actions>
<button ng-if="!vm.user.isBlockingMe && !vm.user.isBlocked" type="button" class="button-
height-32 button-padding-10 follow-icon button-scs button-scs-shadow" user-follow="vm.user" event-
label="user-tile-small"><i class="icon-person-plus"></i></button>
<i class="icon-person-plus"></i>
I am getting Message: no such element: Unable to locate element: messages:
{"method":"css selector","selector":".button-height-32 button-padding-10 follow-icon button-scs button-scs-shadow"}
Did you try
driver.find_element_by_xpath("//button[#event-label='user-tile-small']").click()
This should also work if it's not in an iframe or anything.
driver.find_element_by_class_name("button-scs-shadow").click()

geb cant find checkbox element

there is this piece of code that provides a checkbox following from a link to the T&C.
<div class="checkbox accept_agreement">
<label class="control-label" for="step_data_accept_agreement">
<input type="hidden" name="step_data[accept_agreement]" value="0">
<input type="checkbox" name="step_data[accept_agreement]" id="step_data_accept_agreement" value="1">
<label for="step_data_accept_agreement">
<a target="_blank" href="/lanevillkor/">
<font><font>I agree, have read and stored the terms and conditions</font></font>
</a>
</label>
</label>
</div>
Now, I am working on a spock test using geb, and I try to retrieve the checkbox element
<input type="checkbox" name="step_data[accept_agreement]" id="step_data_accept_agreement" value="1">
to do so i have tried many things without the expected output. i was expected that something like
$("#step_data_accept_agreement").click() would be pretty straight forward but it is not. in the other side if I put $("[for='step_data_accept_agreement'] label").click() it clicks the link.
I tried to become as more specific but nothing looks to return the element correctly.
one of my last attempts was
termsAndConditionsOption(wait: true) { $("#step_data_accept_agreement", name: "step_data[accept_agreement]") }
and the error message, as in the other cases too, was in one sentence
element not visible
What do I miss?
So the solution was to use js to click the checkbox. The simpliest way is:
def agreeOnTermsAndConditionsAccept() {
String mouseClickEvt = """
var evt = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
arguments[0].dispatchEvent(evt);
"""
browser.js.exec(termsAndConditionsOption.firstElement(), mouseClickEvt)
}
Geb provides js support to work with javascript, as we find in the documentation. Also another link shows how to simulate a click event with pure javascript.
This was required as the checkbox cant be found as it is hidden. With javascript we can 'see' the position of the element and perform an action in the location that we want. iniMouseEvent can be used as well as it is documentanted here

Cannot find a way to tap() this element (wd,nodejs)

I have a DOM like this:
<form id="frmResendPassword" role="form" method="post">
<div class="form-group">...</div>
<span class="pull-right">
<button type="submit" class="btn btn-sm btn-default">
Resend Password</button>
</span>
</form>
I want to tap the "Resend Password" button.
I have tried many different selectors such as:
elementByClassName("btn-default")
elementById("frmResendPassword")
elementByName("Resend Password")
elementByCss(thecsspath)
ect.... none of them perform the tap()...
however they do not throw a element not found error....
so im confused. can some one please help
update:
Here is the basic automation code... its very basic
it("should send text to phone", function(){
sleep.sleep(5)
return browser
.elementByName("mobileNo")
.sendKeys(usrnme)
.elementByCss("#frmResendPassword button[type=submit]")
.tap()
})
It types the mobile number in fine, however it seems to just ignore pressing the button.
My guess is that the selector is the problem. Try this:
elementByCss("button[type=submit]")
or if that doesn't uniquely identify it, maybe this:
elementByCss("#frmResendPassword button[type=submit]")
In English that means a button with type value of submit that has an ancestor of a form where the id(#) is frmResendPassword
This is how I solved it, thanks to mrfreester
it("should send text to phone", function(){
sleep.sleep(5)
return browser
.elementByName("mobileNo")
.sendKeys(usrnme)
.elementByCss("#frmResendPassword button[type=submit]")
.click()
})

Unable to upload files via file_field using watir and chromedriver

I am using ChromeDriver 2.25; Watir 6.0.1 and Chrome v.55
I have the following problem :
irb(main):006:0> browser.file_field(:id=>'filesUploader').set ("C:\\files\\test.PNG")
This code has slept for the duration of the default timeout waiting for an Element to be present. If the test is still passing, consider using Element#exists? instead of rescuing
nknownObjectException
Watir::Exception::UnknownObjectException: element located, but timed out after 30 seconds, waiting for true condition on {:id=>"filesUploader", :tag_name=>"input", :type=>"file"}
HTML:
<div class="fileFormInner">
<input id="uploadFileAjaxData" value="{"d": {"path": "/"}, "f": "uploadFile", "u": 14696528}" name="d" type="hidden"> <input value="uploadFile" name="f" type="hidden">
<input id="filesUploader" name="file" multiple="" onchange="MP.Files.Uploader.uploadOnChange(this);" style="cursor:pointer; font-size: 36px; width: auto;" type="file">
</div>
Next I check if this file_field is visible and does it exist :
irb(main):007:0> browser.file_field(:id=>'filesUploader').exist?
=> true
irb(main):008:0> browser.file_field(:id=>'filesUploader').visible?
=> false
This all works fine in Firefox, but doesn't work in Chrome. This file_field is visible in Firefox, but is not visible in Chrome.
Does anyone have some ideas how can I fix this issue?
I was having the same issue, but was able to resolve it by following the work around suggested by louisjohnson-echo360.
The key is to set Watir.relaxed_locate to false before calling set on file_field.
So for your specific problem, the solution would be:
Watir.relaxed_locate = false
browser.file_field(:id=>'filesUploader').set ("C:\\files\\test.PNG")
Watir.relaxed_locate = true

How to click on '+ Add to Friends'

I am trying to click on '+ Add to Friends'.
browser.div(:class, "+ Add to Friends").click and browser.div(:text, "+ Add to Friends").click
But get: Element is not currently visible and so may not be interacted with
<div data-friend="5004" onclick="return {'b-profileFriendsButton': {'friend': '5004' }}" class=" b-profileFriendsButton_mode_0 i-bem b-profileFriendsButton_js_inited">
<div class="b-profileFriendsButton__text b-profileFriendsButton__text_mode_2">Friends</div>
<div class="b-profileFriendsButton__hover b-profileFriendsButton__hover_mode_2 b-profileFriendsButton__deleteFromFriends">– Delete From Friends</div>
<div class="b-profileFriendsButton__text b-profileFriendsButton__text_mode_1">Friends</div>
<div class="b-profileFriendsButton__hover b-profileFriendsButton__hover_mode_1 b-profileFriendsButton__deleteFromFriends">– Delete From Friends</div>
<div class="b-profileFriendsButton__text b-profileFriendsButton__text_mode_0 b-profileFriendsButton__addToFriends">+ Add to Friends</div>
<div class="b-profileFriendsButton__hover b-profileFriendsButton__hover_mode_0 b-profileFriendsButton__addToFriends">+ Add to Friends</div>
</div>
There is no <div> tag with a class attribute of "+ Add to Friends", so browser.div(:class, "+ Add to Friends").click shouldn't work at all. To use a :class locator in this case, you'd do something like this:
browser.div(:class, "b-profileFriendsButton__text b-profileFriendsButton__text_mode_0 b-profileFriendsButton__addToFriends").click
And there are 2 <div> tags containing a "+ Add to Friends" text string, so a compound locator using :text and :index should help identify the correct one. For example:
browser.div(:text => "+ Add to Friends", :index => 0).click
Lastly, try using the when_present method to wait for page elements to become fully enabled:
browser.div(:text => "+ Add to Friends", :index => 0).when_present.click
Please try this.
Since we have two +Add to friends. Use Regular expression and index properties to click.
browser.div(:class=>/addToFriends/, :index=>0).click
browser.div(:class=>/addToFriends/, :index=>1).click
Here is the solution:
browser.div(:class => "b-profilePage__button").click
browser.div(:class => "b-profileFriendsButton__hover b-profileFriendsButton__hover_mode_0 b-profileFriendsButton__addToFriends").click

Resources