Unable to upload files via file_field using watir and chromedriver - watir

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

Related

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

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

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()
})

TYPO3 Indexed Search not working

I'm using the TYPO3 version 8, I have installed the indexed_search form box with typoscript
50 = COA
50 {
stdWrap {
wrap = <div id="searchcontainer">|</div><div class="clearboth"></div>
required = 1
}
10 = TEXT
10 {
wrap = <form id="searchbox" name="searchbox" action="|" method="post">
typolink.parameter = {$searchPID}
typolink.returnLast = url
if.isTrue = {$config.tx_realurl_enable}
}
20 = TEXT
20 {
value = <form id="searchbox" name="searchbox" action="/" method="post">
if.isFalse = {$config.tx_realurl_enable}
}
30 = COA
30 {
10 = TEXT
10{
wrap = <input type="hidden" name="id" value="|" />
value = {$searchPID}
if.isFalse = {$config.tx_realurl_enable}
}
20 = TEXT
20 {
wrap = <input type="text" id="swords" name="swords" value="|" size="20" onfocus="this.value='';" />
value = {$searchTEXT}
}
30 = TEXT
30 {
wrap = <input type="submit" id="searchbutton" value="" />
}
}
40 = TEXT
40 {
value = </form>
}
}
When I click on search, I'm redirected to my search page wich contain the search plugin installed, but no search results or even the keyword is showing. The pages are well indexed and in the backend indexing searched keyword it appears, but not in the frontend, what I'm mising here ? please help!
user2714261 shows, how to deactivate the cHash check for all elements. That might a bit risky in deed. But you can deactive it only for the indexed_search plugin. That won't be any problem, because the indexed_search should not cache anyway. So you jsut can write in your plugin-Setup:
plugin {
tx_indexedsearch {
features.requireCHashArgumentForActionArguments = 0
}
}
That worked fine in TYPO3 8.7.9.
Martin
You can use <f:form> in a FLUIDTEMPLATE to generate a Quicksearch-Form. This way an essential cHash-parameter will be generated and appended to the action-URL, automatically.
TypoScript (Constants)
plugin.tx_indexedsearch.settings.targetPid = 35
TypoScript (Setup)
lib.quicksearch = FLUIDTEMPLATE
lib.quicksearch{
file = fileadmin/Quicksearch.html
settings.targetPid = {$plugin.tx_indexedsearch.settings.targetPid}
}
Quicksearch.html
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<div id="quicksearch">
<f:form action="search" method="post" controller="Search" extensionName="indexedsearch" pluginName="pi2" pageUid="{settings.targetPid}">
<f:form.textfield name="search[sword]" value="{sword}" class="quicksearch-sword" />
<f:form.submit name="search[submitButton]" value="Search" class="quicksearch-submit" />
</f:form>
</div>
</html>
Edit: i found the solution. You have to add something to the typolink ts (my result plugin has _pi2 btw)
wrap = <form id="searchbox" name="searchbox" action="|" method="post">
typolink.parameter = 25
typolink.additionalParams = &tx_indexedsearch_pi2[action]=search&tx_indexedsearch_pi2[controller]=Search
typolink.returnLast = url
typolink.useCacheHash = 1
First Posting:
I don't have the solution right now, but i found something that could help.
I'm having a similar problem with TYPO3 8 and a searchbox. I adapted my HTML of the searchbox, that it fits to the embedded plugin, like this:
<form action="searchresult.html?tx_indexedsearch_pi2%5Baction%5D=search&tx_indexedsearch_pi2%5Bcontroller%5D=Search" method="post" name="searchform" id="searchform">
<input name="tx_indexedsearch_pi2[search][sword]" type="text"/>
<input name="tx_indexedsearch_pi2[search][submitButton]" type="submit" id="submitbutton" value="submit"/>
...
As you can see i have a fixed setup here in my template. What i noticed is, that the embedded plugin obviously doesn't run if you don't send the chash in the action url. Probably you can generate it with your typoscript.
I'm just sure that this is the problem, at least for my case, because when i turn the chash requirements for extbase off, it works ...
config.tx_extbase.features.requireCHashArgumentForActionArguments = 0
but i believe that is a little bit risky and should not be used in production
so generating the chash should be the way to do make it work. just wanted to share what i found out.

GM: Difference in open a new window direct/on button click

First of all, I have no Idea what I'm doing exactly, secondly I hope my english is quite good enough.
My favourite website recently changed its look and feel, therefor I try to reanimate the "old" style via Greasemonkey. So far everything works but I have an issue opening a window for a comment. This comment(field) is now part of the site itself and no loger a free floating window.
What i did is adding this to the script:
var newWin = open('','write a comment','height=300,width=600');
newWin.document.write('<html><head><title>Write a comment</title></head></head><body bgcolor="#555555" text="#000000" topmargin="0" leftmargin="0" style="overflow:hidden;"><form id="commentForm" name="photoComment" action="http://[...]/add_photo_comment/38060403" method="post"reloadUrl="[...]/photo-comments/38060403/de/page/1"data-ua-submit="Fotodetailseite;Kommentar verfassen;Foto;38060403"><div class="media-left"><div class="media-body"><div class="form_row"><textarea id="photoComment_comment" name="photoComment[comment]" required="required" rows="5" class="form-control write-comment" placeholder="Anmerkung"></textarea></div><div class="row fcx-space-tiny"><div class="col-lg-12 text-right"><button type="submit" class="btn btn-primary btn-sm submit-comment"><i class="icon icon-comment"></i>send</button></div></div></div></html>');
Sofar this works for me when inserting the code directly into the script (window opens on entering the site directly)
As far as I wrap it in a function, the new window will be opened but without contetnt:
var input=document.createElement("input");
input.type="button";
input.value="Anmerkung";
input.onclick = createComment;
input.setAttribute("style", "font-size:18px;position:absolute;top:80px;left:40px;");
document.body.appendChild(input);
function createComment()
{
[exactly the same script as above]
};
What am I doing wrong?
Thanks for help

Resources