I'm writing tests that will look within an element which contains 4 href, and create an array of each href within it then click on each one in turn and expect a result.
Looking at the Capybara DSL docs, I can't see a way of scoping within, then calling all, kind of like this:
links = all(:href).within('id-of-element')
I would just leave it as just all(:href) but there are 3 elements containing 4 href, I need to be specific of the element I'm interacting with.
Is there a way to do this?
Capybaras within takes a block and is called on the session, it's not a method you can call on nodes or "array"s of nodes
within("#id") do
find(...) # result scoped to inside element with id
end
Your other option would be to just call find/first/all on a node which scopes it to that node
find("#id").all(...). # results of all are scoped to element with id
Related
I'm facing an issue, that probably is because of my lack of Python knowledge, but I'm trying to verify checkboxes that are contained in a dropdown. Because the web app being developed might contain several of this dropdown lists in different pages I wanted to create a keyword I could use by only passing the generic class of the div and checkbox
At the moment I have the following keywords for this matter:
Verify Container Items
[Documentation] This keyword should be used on simple list items where the elements can be tested for redirect funtionality.
... Parameters:
... closed_locator: generic class for the closed container
... opened_locator: generic class for the opened container
... locator: generic class for a given web element inside the container
[Arguments] ${closed_locator} ${opened_locator} ${item_locator}
${container_closed_xpath}= Set Variable ${closed_locator}
${container_opened_xpath}= Set Variable ${opened_locator}
#{container_xpath}= Create List ${closed_locator} ${opened_locator}
${container_count}= get element count ${container_xpath}
${container_names}= Create List
FOR ${i} IN RANGE 1 #{container_count} + 1
${element_closed}= Set Variable (${container_xpath[0]})[${i}]
${element_opened}= Set Variable (${container_xpath[1]})[${i}]
${name}= Get Text xpath=${element[1]}
Append To List ${names} ${name}
Click Element ${element_closed}
Verify Contained Items ${item_locator}
Click Element ${element_opened}
END
Verify Contained Items
[Arguments] ${item_locator}
${item_xpath}= Set Variable ${item_locator}
${item_count}= get element count ${item_xpath}
${item_names}= Create List
FOR ${i} IN RANGE 1 ${item_count} + 1
${element}= Set Variable (${item_xpath})[${i}]
${name}= Get Text xpath=${element}
Append To List ${item_names} ${name}
Click Element ${element}
END
This is where my knowledge of python might be screwing me. in the first keyword I pass a xpath for the closed dropdown, opened dropdown which I store in a list which is going to be used in the FOR count, and with this I want it to click on the closed dropdown to open it, call the other keyword to tick all the checkboxes, click on the opened dropdown to close it and increment the values of both closed or opened dropdown and iteract with the other dropdowns/ checkboxes.
However when running the test I get the error:
AttributeError: 'list' object has no attribute 'startswith'
At this point I tried it all and I'm stuck in this, I started to do a workaround with other keywords, but I wanted to know if its possible to do it with a list of two variables or if I'm just wasting my time and probably brain cells.
BTW I'm using SeleniumLibrary and Collections libraries and PyCharm to code
On the selection of one drop-down multiple drop-down generated automatically as per selected value of first drop down.
The value of first drop down is between 1 to 7.
If I select 4 in parent then 4 child drop-down generate.
How to handle this problem by using geb page object and utilize it in test spec.
Sample UI of mentioned problem
How are the child drop-downs generated? Is there some JavaScript involved or are the children already on the page and just not displayed?
For the first option, I suggest you execute the JS script via Geb how to deal with dynamic content.
You can pass parameters to the script (so you can pass what you select in the drop down).
In the page object that describes your page you can do something like:
parent{$("select", id: "parent")}
children {}
and add child dropdowns to children after. (I don't have enough details to give you a precise answer here.)
If the children are just not displayed until you select an option in the parent dropdown you can define them from the beginning in your page object. Even if you don't see them, they exist in the document your browser will interpret.
Is it possible to get List (or any other component from RV) to render itself like an UL>LI list or specifically like React Bootstraps ListGroup.
Currently I can not see an option to get the outer element (LIST) to render anything other than a DIV.
So my use case is really that each row should be a ListGroupItem (e.g. li with BS classes applied) and the container should be a ListGroup component.
Short answer: No. This is not supported.
Longer answer: List (like Table) uses a Grid internally. In order for windowing to work, Grid needs 2 wrapper elements around its cells. (Check out the source here. I also made a presentation slide about how it works, if you're interested, here.) Lists (ol, ul) only have 1 wrapper element.
IE 11 has been out just one day as of this posting.
I cannot get an element to go full screen (div or document)
http://msdn.microsoft.com/en-us/library/ie/dn265028
msRequestFullscreen will error 'object does not support this...)
However, the above msdn example will work on passing a target - makeFullScreen(evt.target).
Can I get an div to go fullscreen as in following jquery code?:
var xxx = $('#container');
xxx.msRequestFullscreen();
Or better still: click a button then have a div or the entire document to go fullscreen?
As it stands now, when a click a button, it's the button that goes full screen.
I think this is actually a small misconception of JQuery. JQuery-ing an ID doesn't actually return the element found - it returns a "JQuery object" which allows many actions on that element (or, on a series of elements if you used a class selector)
I don't have IE11 available so I can't test for you, but try this. The [0] should retrieve the element itself.
var xxx = $('#container')[0]; xxx.msRequestFullscreen();
Your code:
var xxx = $('#container');
xxx.msRequestFullscreen();
This is wrong, because you're trying to call a DOM method on a jQuery object.
jQuery calls like $('#container') return jQuery objects. You can do lots of things with these objects, but one thing you can't do is call standard DOM methods. For that, you need an actual DOM object.
jQuery objects contain an array of matching DOM objects, which you can access via [0] for the first one, and [1], etc if there was more than one matching element. So you can do your call by changing your second line as follows:
xxx[0].msRequestFullscreen();
This will call the msRequestFullscreen() on the DOM element rather than the jQuery element, and that should work for you.
In this case, you don't even need jQuery at all, since you're not using any of the jQuery functionality. You could simply use document.getElementById('container') to get the DOM object in the first place rather than the jQuery method. Then you don't need the [0] syntax on the second line because you've already got the DOM object.
Finally, you might want to be careful of course, because this is an IE-specific method; the ms at the front of the name tells you that, which means that your code won't work in other browsers, even if they support the same feature. You need to do it in a cross-browser way. There are some tips on how to do this here: How to make the window full screen with Javascript (stretching all over the screen)
I have added a ComboBox to my CHTMLEditCtrl by passing it in a HTML string.
Then dynamically I add the members(items) to it using IHTMLSelectElement.
Now I want to change the font of one of the items that I have just added.
But when I use item() method on this object, it returns a null. Also when I use get_size on the Object, it returns 0, even though all the items I added in the combobox are visible(and hence I infer all the items are added).
I am not able either to retrieve it using COM methods. Any idea?
Usually the DOM elements are available once the page render is complete.