Is there any way to locate just visible elements with Watir?
I want to locate only visible forms (by the index param) so that Watir would return first or second visible text field.
How is it possible to filter invisible fields / elements?
Is it possible to do that with xpath?
This will return the first visible text field:
browser.text_fields.select {|text_field| text_field.visible?}[0]
You can set text in text field like this:
browser.text_fields.select {|text_field| text_field.visible?}[0].set "text"
This will return the second visible text field:
browser.text_fields.select {|text_field| text_field.visible?}[1]
Please note that element can be visible, but disabled.
Related
I can't acess a textbox on a webpage box , it's a dynamic element. I've tried to filter it by many attributes on the xpath but it seems that the number that changes on the id and name is the only unique part of the element's xpath. All the filters I try show at least 3 element. I've been trying for 2 days, really need some help here.
from selenium import webdriver
def click_btn(submit_xpath): #clicks on button
submit_box = driver.find_element_by_xpath(submit_xpath)
submit_box.click()
driver.implicitly_wait(7)
return
#sends text to text box
def send_text_to_box(box_xpath, text):
box = driver.find_element_by_xpath(box_xpath)
box.send_keys(text)
driver.implicitly_wait(3)
return
descr = 'Can't send this text'
send_text_to_box('//*[#id="textfield-1285-inputEl"]', descr)' #the number
#here is the changeable part on the xpath
:
edit: it worked now with the following xpath //input[contains(#id, 'textfield') and contains(#aria-readonly, 'false') and contains (#class, 'x-form-invalid-field-default')] . Hopefully I found something specific on this element:
You can use partial string to find the element instead of an exact match. That is, in place of
send_text_to_box('//*[#id="textfield-1285-inputEl"]', descr)' please try send_text_to_box('//*[contains(#id,"inputEl")]', descr)'
In case if there are multiple elements that have string 'inputE1' in id, you should look for something else that remains constant(some other property may be). Else, try finding some other element and then traverse to the required input.
I would like to define a new style of ordered lists in asciidoctor that is composed of a fixed uppercase letter and a counter that increments. It has to be document wide. For example
A1. first item
A2. second item
some text
A3. third item
the flow of the text continues
The solution I came up with is as follows, which is heavy and not 100% satisfactory.
[horizontal]
A{counter:ol1}.:: first item
A{counter:ol1}.:: second item
some text
[horizontal]
A{counter:ol1}.:: third item
the flow of the text continues
Is there a simpler solution ? Is there a possibility at least to define a macro that would expand to A{counter:ol1}.::?
You have a couple of choices:
Create a macro in your editor that inserts the required markup (assuming that your goal is to reduce the amount of typing to achieve this effect).
Adjust the markup to specify a custom role and drop the counter:
= My document
:docinfo: shared
[horizontal, role=numbered]
A:: first item
A:: second item
some text
[horizontal, role=numbered]
A:: third item
the flow of the text continues
Then add some custom CSS, via a docinfo file (see: https://asciidoctor.org/docs/user-manual/#docinfo-file), that does the counting for you. This won't work in PDF output.
body {
counter-reset: myli;
}
.hdlist.numbered .hdlist1::after {
content: counter(myli) ". ";
counter-increment: myli;
}
I have a multiple select field that allows multiple selections of colors. I created a formula that would append a prefix of "color-" to each selected list, but it only appends it to the the beginning of the field. I'm not sure how I can split the field results up for the formula to where I can get it showing up for all results.
CASE WHEN {custitemtag_color1} is NULL
THEN ''
ELSE 'color-'||{custitemtag_color1}
END
Results with multiple selections show: color-Black,Lime Green,White
Expected Results need to show: color-Black,color-Lime Green,color-White
What's happening is that NetSuite returns "Black,Lime Green,White" as a single result for the multi-selection, then you're prepending "color-" to that text returned. To work around it within your saved search, you could simply replace any instances of the comma (",") with ",color-":
CASE WHEN {custitemtag_color1} is NULL THEN '' ELSE 'color-'|| REPLACE({custitemtag_color1}, ',', ',color-') END
I have a smart search filter that is filtering news items by tags which all works fine.
The query for the filter dropdown is as follows:
SELECT 'DocumentTags', TagName, TagName FROM CMS_Tag WHERE ##WHERE## ORDER BY ##ORDERBY##
I need to know how to add a default of "All" (essesntially no filter) to this list, but cannot work out how to do it.
The only option I have currently is to tag all documents with "All" tag then this would show up, but hopefully there is another way?
I typically query a default of of empty string, empty string, display text and use a UNION to bind it with the set of results to actually filter by:
SELECT '','','-- Select a Value --'
UNION
SELECT 'DocumentTags', TagName, TagName
FROM CMS_Tag
WHERE ##WHERE##
ORDER BY ##ORDERBY##
This is my jqgrid - $("#list1")
When it loads, i.e. on the gridComplete event, I need to rename the column header texts.
Original column header texts are in this format - Colomn1, Column2 ...
On gridComplete, I change these header texts like this:
$("#list1_Column" + someNumber).text(someText);
However on doing this, I lose the ability to sort columns. Column headers are no longer clickable and hence I cannot sort the grid after this custom programmatic editing.
Similar thing happens when I try changing the texts in the search dropdown list (search modal - using multipleSearch: true)
When, on gridComplete, I change text values in the select list as per the grid column headers, like this -
var select = $('#grid_wrapper #fbox_list1 .ui-widget-content .sf .fields select');
$('#grid_wrapper #fbox_list1 .ui-widget-content .sf .fields select option').remove();
$.each(data, function (i, item) {
select.append('<option value="Column' + item.id + '">' + item.ColumnName + '</option>')
});
...I lose the ability to perform multiple search, i.e. the + and - buttons in the search modal disappear.
How do I get around these two issues? Retaining ability to sort and perform multiple search after having changed column header and search list text values on load.
Please guide.
The column header <th> element has two child elements: one <span> with the text of the column header and another with the sort icons which are hidden the most time. So if you want to change the text manually you should use another selector
$("#list1_Column" + someNumber+ " > span").text(someText);
If you do so you will change the text on the page, but not change the text in the colNames or in the colModel (if you use label property instead of colNames). The text will be used for example to create Multisearch dialog. You can make changes in the colModel with respect of setColProp method or use getGridParam to get reference to any internal parameter of jqGrid (which are objects like inclusive colNames and colModel) and then make any changes which you need.
The best way in my opinion to solve the described problems is to use setLabel method to change the text in the column header:
$("#list1").jqGrid('setLabel','ColumnName','My new Name');
this will solve both problems.