I have a problem selecting option from the dropdown.
The HTML is this:
<div unselectable="on" class="k-widget k-multiselect k-header" style="" title="">
<div unselectable="on" class="k-multiselect-wrap k-floatwrap">
<ul class="k-reset" unselectable="on" role="listbox"></ul>
<input style="width: 25px" class="k-input k-readonly" accesskey="" autocomplete="off" role="listbox" aria-expanded="false" tabindex="0" aria-owns="" aria-disabled="false" aria-readonly="false" aria-busy="false" aria-activedescendant="28dfc7ec-69a2-4a95-ba29-1f94e899c7e3">
<span class="k-icon k-loading k-loading-hidden"></span>
</div>
<div data-bind="source: getTreeValues, value: selectedCrmAttributes.DYN_" data-text-field="name_i18n" data-value-field="attributeId" data-value-primitive="false" data-auto-bind="true" data-role="interestselect" multiple="multiple" style="display: none;" aria-disabled="false" aria-readonly="false">
<option value="DYN_#76ed2b3f-4d64-4d07-8ba7-ab6f133e0c70">one.csv</option>
<option value="DYN_#6f914af1-ba58-4c40-99fe-e874bdf9c47b">two.csv</option>
<option value="DYN_#4cd908d0-6c61-4a15-84e7-f113aa7a8ed4">three.csv</option>
<option value="DYN_#c137cfad-81af-4164-90b1-a518a7595baa">four.csv</option>
</div>
<span style="font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; font-size: 13px; font-stretch: normal; font-style: normal; font-weight: 300; letter-spacing: normal; text-transform: none; line-height: 17.0333px; position: absolute; visibility: hidden; top: -3333px; left: -3333px;"></span>
</div>
I have tried to select the option by this way
And(/^selecting (.*) from (.*)$/) do |item, selection|
find('.dgr-dimensions-row', :text=>selection).find('.k-widget.k-multiselect.k-header').click
#expect(page).to have_content(item) -> returns true
select(item)
end
Where the item is the option i want to select and selection is filter from where I want to select the item.
Example: If I have a filter File and the options are one, two, three, four.
Then the selection is File and the item is one for example.
I'm using
cucumber 2.1.0
ruby 2.1.6
nokogiri 1.6.6.2
capybara 2.4.4
selenium-webdriver 2.47.1
Thanks in advance!
EDITED
I would like to select the option by text, that the ruby step can be reusable. I have many similar fields like this one and it would be useful if I can reuse the same step.
Picture:
EDITED 2
<ul unselectable="on" class="k-list k-reset" tabindex="-1" aria-hidden="true" aria-live="polite" data-role="staticlist" role="listbox" style="overflow: auto; height: auto;">
<li tabindex="-1" role="option" unselectable="on" class="k-item k-state-focused" data-offset-index="0" id="96c13cd6-8365-4e73-a134-6395988822f7">one.csv</li>
<li tabindex="-1" role="option" unselectable="on" class="k-item" data-offset-index="1">two.csv</li>
<li tabindex="-1" role="option" unselectable="on" class="k-item" data-offset-index="2">three.csv</li>
<li tabindex="-1" role="option" unselectable="on" class="k-item" data-offset-index="3">four.csv</li>
</ul>
Capybaras #select only works with visible html option elements. The issue here is that you appear to be using a kendo multiselect widget which hides the real option elements ( btw your html is invalid since option elements are only legally allowed to be inside a select, optgroup, or datalist element) and then generates a visible UI using li elements inside a ul.k-list. From looking at a demo of the kendo multiselect - http://demos.telerik.com/kendo-ui/multiselect/index - it appears the actual ul.k-list element is attached to the page outside of the widget div and therefore a find can't be scoped to the widget, and the ul.list is given an id of "#{id of select hidden in multiselect widget}_list". Since your html doesn't appear to have an id on the hidden element in the widget there is no way to scope with that either. Because of all of that, rather than doing select(item) you should be able to use
find('.k-list li.k-item', text: item).click
to click on the element in the dropdown that becomes visible after you click in the header. It would be better if this find could be scoped to a particular .klist on the page, but hopefully there is only ever one actually visible while you're running the tests.
Related
I click on the input field and popup with items list appears. But I cannot click on any item
cy.get('#field')
.click({force:true}) //popup with items list appers
cy.get('.ant-select-dropdown-menu')
.should('be.visible')
.contains('Item123', { timeout: 20000})
.click({force:true})
Error:
Timed out retrying: Expected to find content: 'Item123' within the element: <ul.ant-select-dropdown-menu> but never did.
I use this html.
I click on the field and popup appears with items list. I want to click on the any item.
html:
<div style="position: absolute; top: 0px; left: 0px; width: 100%;">
<div>
<div class="ant-select-dropdown ant-select-dropdown-hidden" style="width: 180px; left: 883px; top: 477px;">
<div id="753a81bb-579c-4483-f7e5-5527f7c01f3a" style="overflow: auto; transform: translateZ(0px);">
<ul role="listbox" class="ant-select-dropdown-menu ant-select-dropdown-menu-root ant-select-dropdown-menu-vertical" tabindex="0">
<li role="option" unselectable="on" class="ant-select-dropdown-menu-item" aria-selected="false" style="user-select: none;">
Item1 <i aria-label="icon: check" class="anticon anticon-check ant-select-selected-icon"></i>
</li>
<li role="option" unselectable="on" class="ant-select-dropdown-menu-item" aria-selected="false" style="user-select: none;">
Item12 <i aria-label="icon: check" class="anticon anticon-check ant-select-selected-icon"></i>
</li>
<li role="option" unselectable="on" class="ant-select-dropdown-menu-item" aria-selected="false" style="user-select: none;">
Item123 <i aria-label="icon: check" class="anticon anticon-check ant-select-selected-icon"></i>
</li>
<li role="option" unselectable="on" class="ant-select-dropdown-menu-item" aria-selected="false" style="user-select: none;">
Item1234 <i aria-label="icon: check" class="anticon anticon-check ant-select-selected-icon"></i>
</li>
</ul>
</div></div></div>
You can use eq() to get DOM element at a specific index in an array of elements:
cy.get('li.ant-select-dropdown-menu-item', {
timeout: 20000
}).eq(2).click({
force: true
})
I know little about Laravel and Masonry grid layout, but I know how Bootstrap framework works.
I need to change the number of columns in a Boostrap grid for small size devices like a mobile phone. Currently, the number of columns is 3 because the class used is col-xs-4. However, I need to change it to col-xs-6, so that it shows 2 columns.
I don't think it's that hard, but I don't know how Laravel works.
I tried searching for those divs in the whole project so that I could directly change those classes, but I couldn't find anything.
This is an example of one column in a row:
<div class="container-fluid">
<div class="row">
<div class="fw-divider-space hidden-below-xl pt-70"></div>
<div class="col-lg-12">
<div data-animation="fadeInDown" class="row isotope-wrapper masonry-layout c-gutter-5 c-mb-5 animate animated fadeInDown" style="position: relative; height: 798px;">
<div class="col-sm-3 col-lg-3 col-lgx-3 col-xl-3 col-xs-4 col-4" style="position: absolute; left: 0%; top: 0px;">
<div class="vertical-item item-gallery content-absolute text-center ds">
<a href="https://www.tusencuentros.cl/modelo/9/ver" class="item-media h-100 w-100 d-block"><img src="https://www.tusencuentros.cl/storage/fotos_perfil/9-1.jpg" alt="Modelo">
<div class="media-links"></div>
</a>
<img src="https://clubvip.cl/storage/watsapp_logo.png" style="width: 40px; height: 40px; margin-top: 5px;"> <i aria-hidden="true" class="fa fa-phone-square" style="font-size: 36px; color: rgb(255, 255, 255); float: right;"></i>
<div class="item-content" style="background-color: rgb(233, 11, 165);">
<div class="item-title" style="top: -80px; width: 100%;">
<div style="display: inline-flex;">
<p style="font-size: 14px;">CARLITA </p>
</div>
<div>
<p style="font-size: 12px;">CHILENA, 20</p>
</div>
<div>
<p style="font-size: 10px;">Medidas: 94-62-98</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
I expect the classes col-xs-4 to be col-xs-6.
I assume you use laravel blade
You can use dynamic css class in here like
class="col-sm-3 col-lg-3 col-lgx-3 col-xl-3 {{ $isMobile ? 'col-xs-6' : 'col-xs-4' }} col-4"
In the curly blackets : is this mobile device? if yes, I will use col-xs-6 if not I will use col-xs-4
But you need to send the checking of $isMobile from your controller and there is a very simple component for that here jenssegers/agent
After installation you can perform check for mobile device by using $agent->isMobile() method
Finally I could fix it by finding out that the folder with the file that contains those divs was inside a non-public location called "resources". Since I know little about Laravel Blade, I didn't know the directory structure.
The html page contains two containers. Each container has two columns, the left for selectable list items and the right for selected list items. So once you click on the list item it moves from the left column to the right column.
The first container is for associated clients.
The second container is for countries.
They both use similar code without a unique id or name.
HTML code for first container:
<div class="col-sm-12 col-md-6">
<div class="tab-section">
<h3 class="section-header"> Associated Client(s) </h3>
<div class="row">
<div class="col-sm-12">
<div id="ClientControlDiv">
<div style="margin: 0 auto; width: 450px;">
<select id="AssociatedClientList" class="multi-select" name="AssociatedClientList" multiple="multiple" style="position: absolute; left: -9999px;">
<div id="ms-AssociatedClientList" class="ms-container">
<div class="ms-selectable">
<div class="panel-heading ">
<ul class="ms-list" tabindex="-1" style="height: 250px; width: 200px;">
<li id="3ce0a0cc_378d_4477_8787_84033319940f-selectable" class="ms-elem-selectable ms-hover">
<span>(Test) 3M</span>
</li>
</ul>
</div>
<div class="ms-selection">
<div class="panel-heading ">
<div class="panel-title">Selected Client(s)</div>
</div>
<ul class="ms-list" tabindex="-1" style="height: 250px; width: 200px;">
<li id="3ce0a0cc_378d_4477_8787_84033319940f-selection" class="ms-elem-selection" style="display: none;">
<span>(Test) 3M</span>
</li>
HTML code for second container for countries:
<div class="col-sm-12">
<div id="DesignationControlDiv">
<div style="margin: 0 auto; width: 450px;">
<select id="AssociatedDesignationsList" class="multi-select" name="AssociatedDesignationsList" multiple="multiple" style="position: absolute; left: -9999px;">
<div id="ms-AssociatedDesignationsList" class="ms-container">
<div class="ms-selectable">
<div class="panel-heading ">
<ul class="ms-list" tabindex="-1" style="height: 250px; width: 200px;">
<li id="d86b9350_aa83_43c7_bc2b_5fc7f5c6ccae-selectable" class="ms-elem-selectable ms-hover">
<span>Afghanistan</span>
</li>
</div>
<div class="ms-selection">
<div class="panel-heading ">
<ul class="ms-list" tabindex="-1" style="height: 250px; width: 200px;">
<li id="d86b9350_aa83_43c7_bc2b_5fc7f5c6ccae-selection" class="ms-elem-selection" style="display: none;">
<span>Afghanistan</span>
</li>
Once selected the html code is:
<div class="ms-selection">
<div class="panel-heading ">
<div class="panel-title">Selected Client(s)</div>
</div>
<ul class="ms-list" tabindex="-1" style="height: 250px; width: 200px;">
<li id="3ce0a0cc_378d_4477_8787_84033319940f-selection" class="ms-elem-selection ms-selected ms-hover" style="">
<span>(Test) 3M</span>
</li>
Ruby code I tried both:
#b.select_list(:class => "ms-list").li(:text => "(Test) 3M").when_present.select
#b.select_list(:class => "ms-list").li.span(:text => "(Test) 3M").select
Based on the supplied HTML, there's no select_list element. For example:
b.ul(class: "ms-list").li(class: "ms-elem-selectable").span(text: "(Test) 3M").exists?
#=> true
b.ul(class: "ms-list").li(id: /selectable/).span(text: "(Test) 3M").exists?
#=> true
b.select_list(:class => "ms-list").li(class: "ms-elem-selectable").span(text: "(Test) 3M").exists?
#=> false
If you want to click on "(Test) 3M", try something like:
b.ul(class: "ms-list").li(class: "ms-elem-selectable").span(text: "(Test) 3M").click
This is a preliminary answer since you question needs more code to be able to determine what you really are trying to do:
#b.li(:id => /.*selectable/, :text => "(Test) 3M").hover
#b.li(:id => /.*selectable/, :text => "(Test) 3M").click
this assumes that your other list that you do not show in your question has the id like /.*selected/. So Watir should look for all of the li items that have an id that contains selectable and then look for the first one with the text "(Test) 3M").select.
I am using selenium2 and webdriver to automate a Kendo UI and I am unable to control the dropdown to select a model value form the dropdown list. How can I select a value from a Kendo UI DropDownList using webdriver commands?
The issues that it is not coded as a Select element:
<div class="FormLabel">Select Model(s):</div>
<div class="FormInput FixMultiSelect">
<div class="k-widget k-multiselect k-header" unselectable="on" style="">
<div class="k-multiselect-wrap k-floatwrap" unselectable="on">
<ul id="ModelList_taglist" class="k-reset" unselectable="on" role="listbox"></ul>
<input class="k-input" style="width: 25px;" accesskey="" role="listbox" aria-expanded="false" tabindex="0" aria-owns="ModelList_taglist ModelList_listbox" aria-disabled="false" aria-readonly="false" aria-busy="false">
<span class="k-icon k-loading k-loading-hidden"></span>
</div>
<select id="ModelList" data-placeholder="Click Here" multiple="multiple" data-role="multiselect" style="display: none;" aria-disabled="false" aria-readonly="false">
<option value="3">ABCGateway_Model</option>
<option value="25">Jack_Gateway_Model</option>
<option value="4">CC Model_1</option>
<option value="26">Sam_Model_1</option>
</select>
<span style="font-family: 'MyriadPro-Regular',Tahoma,Geneva,sans-serif; font-size: 13px; font-stretch: normal; font-style: normal; font-weight: 400; letter-spacing: normal; text-transform: none; line-height: 16px; position: absolute; visibility: hidden;"></span>
</div>
</div>
</div>
Just wrap your WebElement into Select Object as shown below
Select dropdown = new Select(driver.findElement(By.id("identifier")));
Once this is done you can select the required value in 3 ways. Consider an HTML file like this
<html>
<body>
<select id = "designation">
<option value = "MD">MD</option>
<option value = "prog"> Programmer </option>
<option value = "CEO"> CEO </option>
</option>
</select>
<body>
</html>
Now to identify dropdown do
Select dropdown = new Select(driver.findElement(By.id("designation")));
To select its option say 'Programmer' you can do
dropdown.selectByVisibleText("Programmer ");
or
dropdown.selectByIndex(1);
or
dropdown.selectByValue("prog");
Happy Coding :)
I have a sub grid that has a status column defined. I would like to disable the Add button on its navGrid until subgrid's status column's value is 'Completed'.
Here is a snippet of the HTML that is being generated that I'm (unsuccessfuly) trying to manipulate: (I think I need to use the first and last elements)...???
<div id="USAttorneyFoldersGrid_43" class="tablediv">
<div id="gbox_USAttorneyFoldersGrid_43_t" class="ui-jqgrid ui-widget ui-widget-content ui-corner-all" dir="ltr" style="width: 826px;">
<div id="lui_USAttorneyFoldersGrid_43_t" class="ui-widget-overlay jqgrid-overlay"></div>
<div id="load_USAttorneyFoldersGrid_43_t" class="loading ui-state-default ui-state-active" style="display: none;">Loading...</div>
<div id="editmodUSAttorneyFoldersGrid_43_t" class="ui-widget ui-widget-content ui-corner-all ui-jqdialog jqmID1" dir="ltr" style="width: 300px; height: auto; z-index: 950; overflow: hidden; top: 294px; left: 136px; display: none;" tabindex="-1" role="dialog" aria-labelledby="edithdUSAttorneyFoldersGrid_43_t" aria-hidden="true">
<div id="gview_USAttorneyFoldersGrid_43_t" class="ui-jqgrid-view" style="width: 826px;">
<div id="rs_mUSAttorneyFoldersGrid_43_t" class="ui-jqgrid-resize-mark"> </div>
<div id="p_USAttorneyFoldersGrid_43_t" class="scroll ui-state-default ui-jqgrid-pager ui-corner-bottom" style="width: 826px;" dir="ltr">
<div id="pg_p_USAttorneyFoldersGrid_43_t" class="ui-pager-control" role="group">
This is my selector that doesn't appear to work:
$('#USAttorneyFoldersGrid_43').navGrid('pg_p_USAttorneyFoldersGrid_43_t', { add: false });
What am I missing here?
You posted almost no code, but I hope that my old answer with the demo gives you information which you need.