nightwatchjs selector is not selecting an attribute with space - selenium

I have a few pages on which I am running nightwatchjs to execute an end to end test.
<div role="tab" aria-selected="true" title="My TV"><span>MyReal TV</span></div>
I have a few tabs that I try to verify using code similar to below:
.verify.elementPresent('div[role="tab"][title="Portfolio"]', 1000)
The above works fine for the Portfolio tab. However, I have two tabs that fail and is returning not found. My Tv and Daily Report . Below fails for My Tv:
.verify.elementPresent('div[role="tab"][title="My Tv"]', 1000)
The Daily Report fails as well. I am wondering if it has something to do with the space in my title? Is there anything else I am doing wrong?

It turns out the url was wrong in my case. It was frustrating, spent hours to learn this.
Something like below was returned for the url
http://stackoverflow.com//questions
Instead of
http://stackoverflow.com/questions

Related

How to get &#8212 to display as an em dash when interpolating

On a page I'm working on, I'm trying to get the title of a blog post to read as Sleep—It's frustratingly Important., where there is an em dash between Sleep and It's. Previously I had this hard-coded as
<h2 class="post-title"><router-link to="/posts/1">Sleep&#8212It's frustratingly Important. </router-link></h2>
which was working fine. I want to generalize this, so in my Rails back end I have the post title stored as Sleep&#8212It's frustratingly Important.. But when I insert the post title via interpolation
<h2 class="post-title"><router-link to="/posts/1"> {{ this.posts[0].title }} </router-link></h2>
It doesn't insert the em dash. It displays as "Sleep&#8212It's frustratingly Important."
Why isn't the html recognizing that &#8212 should be changed to an em dash? And how do I fix this issue?
Content between {{ and }} is expected to be an expression that resolves as plain text. It gets converted into a text node. It does not get treated as HTML.
If you want an em-dash, then use a real em-dash: —.
You could also look at dangerouslySetInnerHTML, but it is named that way for a reason.

Get the first child node using the Internet Explorer COM object

I got a website with the following code:
<div id="past">
<div data-rollid="99999" class="ball kugel-2">2</div>
<div data-rollid="99998" class="ball kugel-2">2</div>
<div data-rollid="99997" class="ball kugel-2">2</div>
I want to get this number "2". I know that I can pickup the "past" by
past := wb.document.getElementById("past")
but how to get the value from the first child node?
You don't give a lot to work with, but you might try, for the first "undertag":
wb.Document.getElementByID("past").childnodes.item[0].innerText
For the second "undertag":
wb.Document.getElementByID("past").childnodes.item[1].innerText
etc.
Else, look at something like this:
wb.document.body.querySelector("data-rollid='99998']").innerText;
or
wb.document.getElementByID("past").querySelector("data-rollid='99998']").innerText;
or even
wb.document.getElementByID("past").childnodes.querySelector("data-rollid='99998']").innerText;
Which might work (you might have to play around with the syntax) . . .
Hth,
This can get you all the elements of a certain class:
elements:=ie.document.getElementsByClassName("ball kugel-2")
Or you can do this:
past:= wb.document.getElementById("past")
children:=past.children
while(a_index <= children.length, i:=a_index-1)
msgbox, % children[i].innertext

Selenium preceding-sibling::text() not working

I am having issues with selenium using the next xpath "./preceding-sibling::text()"
I don't understand why, my first thought was that IE wasn't supporting that xpath statement but it didnt work on chrome neither.
What I am trying to do is to verify if a radio button have a certain text "near" it. For example if a radio button is like this
<div>
<label> Yes <input name='radioBtn'></input></label>
<label> No <input name='radioBtn'></input></label>
</div>
This is a simplified scenario where I need to check the "yes" radio button, so what I am doing is to search for the radiobutton and check if it preceding-sibling::text(), but selenium is cant find any element. I know the Xpath works because I test it on chrome developer tools and it returns the text "Yes".
I can't do something like 'input[1]' because I can't be sure that the first one will be always that have the Yes text.
Any idea why isn't this working on selenium? and if there is any work around?
I got to a work around but is kind of specific to the problem. But let's answer the questions 1 at the time.
Any idea why isn't this working on selenium?
It's not working because selenium don't support text elements, so even when selenium find the element it cant map it to a selenium object, i didn't see it because my code hided the selenium exception. The Exception throw is the next one:
An unhandled exception of type
'OpenQA.Selenium.InvalidSelectorException' occurred in WebDriver.dll
Additional information: invalid selector: The result of the xpath
expression "./preceding-sibling::text()" is: [object Text]. It should
be an element
Is there any work around?
Yes it is. What I did was to run a java script using the selenium IJavaScriptExecutor. With the script I revised the preceding sibling text and return it as a string so if the text was equal to the thing I was looking for (i.e Yes) trhat means that is the radio button I was looking for.
The code looks is similar to this (it can have some sintax errors since I didn't copied from the source):
string script = "function GetPrecedingText(node){"+
"var result = document.evaluate('./preceding-sibling::text()[1]', node, null, XPathResult.STRING_TYPE, null);"+
"return (result==null) ? '' : result.stringValue.trim();}"+
"return GetPrecedingText(arguments[0])";
string result = ((driver as IJavaScriptExecutor).ExecuteScript(script, SeleniumElement)).toString();
Hope someone can find this useful :) and thanks for all that tried to help me :)

Selenium webElement.clear() doesn't work with phantomJS but yes with Firefox

I am trying to use PhantomJS as a browser to make a selenium test, but I have a problem with an input.
This input is a calendar (is not type date, is text but modified by JavaScript).
First of all, I have this using FirefoxDriver and works perfectly:
webElement.Clear();
webElement.SendKeys(date);
but, using PhantomJSDriver jumps an exception which says this:
{"errorMessage":"Element must be user-editable in order to clear it.","request":{"headers":{"Accept":"application/json, image/png","Connection":"Close","Content-Length":"0","Content-Type":"application/json;charset=utf-8","Host":"localhost:53291"},"httpVersion":"1.1","method":"POST","post":"","url":"/clear","urlParsed":{"anchor":"","query":"","file":"clear","directory":"/","path":"/clear","relative":"/clear","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/clear","queryKey":{},"chunks":["clear"]},"urlOriginal":"/session/a1e4cdb0-b901-11e4-befc-c3b28b46e8f3/element/%3Awdc%3A1424437741971/clear"}}
is very extraneous because in Firefox works perfectly,
what can I do to send the data?
Also I tried to sen this data without clear it, but the default value is 20/02/2015 and when i send something just add after the current text: 20/02/201530/03/2015 and doesn't work.
attribute .text doesn't has setter, the same for getAttribute().
thanks for all,
Ivan.
#edit1: html
<input type="text" aria-haspopup="true" title="" value="20/02/2015" name="id0" id="id0" class="bg datetime hasDatepicker">
Finally i found how to do this, probably is not the best way, but in my case works.
I send the data by JavaScript with javascriptExecutor
((IJavaScriptExecutor)_driver).ExecuteScript("document.getElementById('id0').value='" + date+ "'");

protractor getText returns empty string for non-empty element

I have issues getting the text from an element in protractor. For other elements of the page it works as expected, just not for this one :/
<p class="error theme-info-i ng-binding ng-scope" ng-if="firstFormError && form.$invalid" ng-click="goToErrorField(firstFormError)">
<span class="emphasize ng-binding">User ID</span> (The user ID is required.)
</p>
I can locate both elements without problems using by.className, and getInnerHtml/getOuterHtml works as expected. However getText returns an empty string for both.
Found the reason ... its a two-step registration where the first step has the same notification area and just gets hidden. For reasons beyond my comprehension the devs update both notification areas (not just the one on the current page), so inner/outerHtml just seemingly returned the "correct content" and because the first area was hidden, getText returned empty as by spec.
I think I'm gonna file some internal bug report now wtf we are doing with those notifications ;)
You can try
var firstName = element(by.model('firstName'))
expect(firstName.getAttribute('value'))
This gives you the value of the input box.
Had the same problem.
expect(element(By.css('span.emphasize.ng-binding')).getAttribute('textContent'))...
Seems to work just fine for me (this of course if you have only one span with those classes or is the first one. else you need to be more specific. But anyway if you still need to solve the problem try with .getAttribute('textContent') )