Clicking in a dropdown with scroll in Capybara - automated-tests

I'm having a problem with my dropdown, It uses selectize to make the dropdown, but when the number of options is too big it adds a scroll to the dropdown and when I try to click in some option that is not seen (that you need to scroll it to see) the capybara thinks the option is there and click out of the input where the option would be without scrolling. There's nothing changing the visibility (ordering it to search for not visible elements don' work either)

you can click a visible element in drop-down than send the :arrow_down native key to simulate down key action. You should do this until the element visible, then click the active option.
Check this for selectize.js home page:
find("#select-country-selectized").click()
while(true)
break if find(".option.active").text == "Benin"
find("#select-country-selectized").native.send_keys(:arrow_down)
end
find(".option.active").click

The example of gunesmes was very helpfull, I made some changes like making the break one line up because otherwhise it would always jump the first option and changing the find for has_css? because find returns an error and has_css? returns true or false. I also changed the first find because I use cocoon and I need always to fill the last input generated. The final result was like this:
def scroll_dropdown(user)
all('input[id$="_user_id-selectized"]').last.click
while(true)
break if page.has_css?(".option.active", text: user, match: :prefer_exact, wait: false)
all('input[id$="_user_id-selectized"]').last.native.send_keys(:arrow_down)
end
find(".option.active").click
end

Related

"Run keyword if"- want to perform double click on a button with this Built in function

So, in brief, i have to perform click on one button and validate for one of the panels whether it is visible or not. So problem starts from here. sometimes it is visible after 2 clicks, and sometimes 1 as per some prerequisite(this is not a bug). Now i start with the solution like if the specified element is not visible then again click on that button and (2nd condition--)if it is visible then go with simple logic as it is.
Run Keyword If Element Should Not Be Visible xpath=//div[#id='menu-container'] Click Button css=[ng-click="toggleMode()"]
I am using Run keyword if-Built in function, Could anyone give me heads up how i can tackle this.
You can first check if the element is not visible and click, only if the status is True.
${status}= Run Keyword And Return Status Element Should Not Be Visible xpath=//div[#id='menu-container']
Run Keyword If '${status}'=='True' Click Button css=[ng-click="toggleMode()"]

How to figure out the index of a ToggleGroup's selected toggle?

I'm trying to select an item from a list that's sorted the same way as a ToggleGroup I have besides it. However, I found that toggleGroup.getToggles().indexOf(toggleGroup.getSelectedToggle()) always returns -1 (visible in the IndexOutOfBoundsException thrown as I pass it). Is there another way of figuring out the index, or am I at a loss with my approach and need to figure out something completely different?
UPDATE: Apparently, for the first time an item is selected (I have this code attached to changes of selectedToggleProperty()), it works fine (I just get no notice of it because the elements I make visible have no proper layout). However, when an item is selected while another item already is selected, getselectedToggle() becomes null, causing aforementioned behavior.
All of the JavaFX toggle controls have a property called UserData. You should use that to create the links between the toggles and data list. Relying on the index of the toggles in the toggle group is probably a bad idea.

QTableWidget Scrolling With Selected Item

So i am using a QTableWidget as a logger of sorts for a user, with new rows being inserted at the top, and bottom ones falling off eventually as i read in updates every second or so.
I am currently running these 3 commands to keep the user from being able to do anything with the widget.
summaryTable->setSelectionMode(QAbstractItemView::NoSelection);
summaryTable->setFocusPolicy(Qt::NoFocus);
summaryTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
This works, the user cant select a box(doesnt get highlighted more on that later), cant edit a box, all is good.
Except even if a user clicks on a cell, even though its not highlighted visibly there is still something allowing it to be selected such that when that cell gets "pushed" down below the current scroll area from inserts at the top the table begins scrolling down to follow this cell all the way to the bottom.
Obviously this is confusing, if a user clicks a cell within a few seconds its going to keep scrolling them down the table over and over again and it becomes a fight for them to scroll back up and click on a header or something to prevent future scrolling.
How do i prevent this? I thought by preventing selection and turning off what i did it would stop this, but there is still some type of selection happening within QT even if its not visible as its tracking the selected cell.
Oops, didnt realize there is a SetAutoScroll method, setting this to false fixed the issue.
This Method May Work QTableWidget::scrollToItem() or
QTableWidget::scrollTo() is will Work :)
You can manually scroll the item by putting row index as -
self.ui.tableWidget.verticalScrollBar().setValue(index)
OR
You can auto scroll the item by current index:
row = self.ui.tableWidget.currentIndex().row()
self.ui.tableWidget.verticalScrollBar().setValue(row)

multiselect in angular-ui-select bootstrap- keep items in menu list?

Is there a way to keep items in the dropdown list in an angular-mutliselect-ui-select control?
I want to click an item, so it is added as selected but keep it in the list (if it is clicked again- nothing should happen).
Straightforward hack is to change $select.removeSelected = true; to false in select.js. A small example is here (see script.js, line: 1244), may be there is a way to do it externally without modifying script.js.

Can't click overlapped element within a popup(not main window),how to scroll it to view?

As you can see,I can click the first check box(PRODUCT-323),but can't click the second.After a long
trying,I find it is because the second doesn't get scrolled to view(Is it intented by tool design or a bug?).So how to scroll this popup div to ensure the second get shown?
Actually,I have tried this,but failed
((JavascriptExecutor)driver).executeScript("document.getElementById("pupop").scrollTo(0,30)");
Can you please share which version of WebDriver are you using?
If I remember correctly, Version 2.16 or so had a known issue with locators not scrolling into view. The reason being,, they were using the position co-ordinates of the center of the element to bring focus and in this case, the center is hidden from view. This was solved in later versions.
There are a couple of approaches.
1) Try to perform some action on an Element that is completely hidden from view.This will bring the element fully into view and you will be able to access it.
In this case, try to access the checkbox in 3rd or the 4th row, you will be able to bring focus there. Then access the 2nd row.
2) Do a Driver.Manage().Window.Maximize() [This is in c#]. This will also bring the element into view.
It is a good practice to avoid a window with both scroll-bars. By maximizing it you will reduce the window for such errors.
Hope this is useful.
Did u try the keyboard options?? ctrl+ down arrow through script???
Or in the worst case use tab to focus on to that checkbox.. I works in OpenScript and RFT this way.
1) To click the second checkbox: You can use the xpath to find that element. In xpath you can easily get the table row id for each checkbox which will gets incremented in their ID.
2) To scroll you can use the below code:
JavascriptExecutor js = (JavascriptExecutor) webdriver;
js.executeScript("scroll(0,0);");

Resources