Wrong xpath for nav html tag - eclipse

I m trying to find element using xpath for tag
<nav id="nav">... </nav>
this works:
WebElement navigationPane = firefox.findElement(By.className("nav"));
but this does not:
WebElement navigationPane =
firefox.findElement(By.xpath("//nav[#id='nav')]"));
How do I make it valid expression in xpath?

In the xpath expression, you've meant to use #class instead of #id. And, there is an extra parenthesis inside. Here is the fixed version:
//nav[#class = 'nav']
After finding an HTML block in your question (made it visible with an edit), I've realized that there is an id attribute set on the element, not class. In this case, you should use the following expression:
//nav[#id = 'nav']
Note that by.id would be an easier and faster way to find the element:
WebElement navigationPane = firefox.findElement(By.id("nav"));

Related

ag-grid: using fullWidth row with angular 1.x directive

I'm trying to render ag-grid with a fullWidth template, that is actually a directive.
gridOptions: {
fullWidthCellRenderer: function(node) {
var el = angular.element('<div />');
el[0].innerHTML = '<div directive="node.data"></div>';
var tpl = $compile(el)($scope);
return tpl[0];
}
The directive expects a model (from 'directive' attribute) but gets undefined.
I'm guessing there are scope issues here, and I do not want to stringify my data in the html template.
How can I pass the data object into my directive?
Thank you
I managed to solve this in 2 ways:
first is to create a child scope from $scope with `$scope.$new()', assign the node variable to it, and compile to template with it.
second, probably better, is to return the element with no $compile and use
angularCompileRows: true in gridOptions.

Selenium nested query to find top parent and then a child under that

I came across a scenario in selenium as given below:
Find a <span> contains text span-text and find it's parent node (not the immediate parent but the parent after traversing all levels up the DOM tree) with class parent-class and under that parent node find a <img> node with class img-class
Sample:
<div> -(1)
<div> -(2)
<div> -(3)
<span> -(4)
<div> -(5)
<img> -(6)
The way I am looking at it is - find (4) first then find its first ancestor (1) and then find (6) which actually comes under (2). I would prefer a nested query even if it looks complex.
Any help?
This should do what you want. I'm assuming for now that the span-text is innerText and not some attribute. If it's an attribute, this will probably get a lot simpler.
Basically we grab all the DIVs with a class of parent-class and loop through them looking for a child SPAN that has an innerText of span-text. Once we find it, we know we have the right parent so we find the child IMG with class `img-class'. I added the line to write out the found tag so that you can quickly verify that it's the right one.
List<WebElement> parents = driver.findElements(By.cssSelector("div.parent-class"));
for (WebElement parent : parents)
{
List<WebElement> spans = parent.findElements(By.tagName("span"));
for (WebElement span : spans)
{
if (span.getText().contains("span-text"))
{
WebElement found = parent.findElement(By.cssSelector("img.img-class"));
System.out.println(found.getAttribute("outerHTML")); // write out the element to the console to verify
}
}
}

Get back the webdriver.Locator out of an elementFinder

Given I have the elmFinder variable:
var elmFinder = element(by.css('.thing'));
What if i need to get back the webdriver.Locator, a.k.a locator strategy? i.e.
elmFinder.??? //=> by.css('.thing')
I'm looking after the function ??? if it exists.
UPDATE:
This feature has been merged and we can now do:
elmFinder.locator();
UPDATE:
This feature has been merged and we can now do:
elmFinder.locator();
Old answer:
You cannot. The element finder does not keep a reference to the locator:
https://github.com/angular/protractor/blob/master/lib/protractor.js#L103
What I typically do is store the selector in it's own var, and then place that string into the selector, so I can use both interchangably:
var cssThingSelector = '.thing';
var elem = $(cssThingSelector);
Something like that.
Edit:
I will also add that you can nest findElement calls from selenium webelement objects.
So, if there is another item in the inner html of the .thing web element (say, a span tag), you could just nest another findElement call:
var spanElem = elem.$('span');
You can do this as much as you'd like.

Wicket DropDownChoice Format

Whenever I do something like someString = object().name + " / " object2().name; in the toString() of an object, and load the array of objects into a wicket dropDownChoice, the dropDownChoice disregards the spacing of the strings.. So I'd rather have something like:
Role / Site
Drop Down Menu: RoleName / SiteName
but instead no matter how much spacing I put it will always display:
RoleName/SiteName in the drop down choice... any ideas? I tried doing:
object().name + "&nbsp/&nbsp" object2() because I wasn't sure how wicket processes the string into the option tags, but that didn't work either.
any ideas?
Thanks!
Figured it out..
doing
toString()
{
return "object().name + "&nbsp/&nbsp" object2().name"
}
this ended up working when I called:
ssaIDRolesDropDownList.setEscapeModelStrings(false);
//ssaIDRolesDropDownList is a reference to my dropDownChoice
This has nothing to do with Wicket; Elements like dropdowns or the infamous input type="file"
are rendered OS specific:
Preserve whitespace in html select element options using "white-space: pre" NOT working

How to define a `separator` tag in play-1.x without modifing play's source code

I want to define a tag separator tag, which inside a list tag, can add separator between items.
The sample code is:
List<String> users = new ArrayList<String>();
users.add("Jeff");
users.add("Mike");
#{list users, as: 'user'}
#{separator ' + ' /}
<span>${user}</span>
#{/list}
If I don't use the separator tag, the code will be:
#{list users, as: 'user'}
${user_isFirst ? '' : ' + '}
<span>${user}</span>
#{/list}
The generated html code will be:
<span>Jeff</span> + <span>Mike</span>
I tried defined a fastTag:
public static void _separator(Map<?, ?> args, Closure body, PrintWriter out, GroovyTemplate.ExecutableTemplate template, int fromLine) {
Object value = args.get("arg");
// TODO how to get the value of `as` defined in parent `list` tag?
out.print(value);
}
But the problem is I can't get the value of as defined in list tag (which is user) in this case.
You can create a custom list tag in groovy like this
#{list items:_arg, as:'tmp'}
%{
attrs = [:]
attrs.put(_as, tmp)
}%
#{ifnot tmp_isFirst}${_sep}#{/ifnot}
#{doBody vars:attrs /}
#{/list}
and use it like this
#{myList users, as:'user', sep:','}
${user}
#{/myList}
You should trace into your FastTag implementation. I think you'll see all the variables in scope inside the args map. This is from memory - so, sorry if not.
That said, I think it might be simpler if you copy the Java code for #{list} and add a new parameter, like
#{list users, as: 'user', separator: '+' }
and handle the logic in there. It seems a bit cleaner too from a design point of view - if it is a separator, how come you can put it anywhere you like in the code (and why not put it in twice!).
A final option is to look at Groovy or Java collection operators. http://groovy.codehaus.org/groovy-jdk/java/util/Collection.html