How to select repeated element with Capybara - ruby

I know how to get the first element, but how can I get the second or third element found with that class x ?
Only way is by choosing from an Array like below? If so, starts at zero or one ?
find(".element")[1]

you can do
find(".element:nth-of-type(1)")
find(".element:nth-of-type(2)")
find(".element:nth-of-type(3)")
or
all(".element")[0]
all(".element")[1]
all(".element")[3]

Related

Finding an element by AccessibilityId and index

I have multiple buttons with the same accessibilityID. I want to get the 3rd one.
Getting the first one is easy with
let severityItems = app.buttons["MyListItems"].firstMatch
But if I want the 3rd one and do it this way
let severityItems = app.buttons["MyListItems"].element(boundBy: 2)
I get an error: Value of type 'XCUIElement' has no member 'element'
Strange. I seems to get an array. If I po it in the debugger it shows me the elements correctly. How can I get the 3rd element?
app.buttons["MyListItems"] returns an XCUIElementQuery, not an array of elements. If you look at the documentation for that you'll see a property called allElementsBoundByIndex, which returns an array of elements.

Within robot framework find an xpath within an element variable

I have currently got a situation where I need to get all elements on a page, iterate through the elements 1 by 1 and within each element, I want to see if a certain other element exists.
To make it more clear, this is my loop:
${elements} = Get WebElements //li[#class='product-item--row js_item_root ']
FOR ${item} IN #{elements}
This is the part where I need to check within ${item} if the xpath exists:
//*[contains(text(), '${companyname}')]
END
So basically, I have 24 elements on my page which have the xpath
//li[#class='product-item--row js_item_root ']
I have 1 element on my page which can be located by xpath
//li[#class='product-item--row js_item_root ']//*[contains(text(), '${companyname}')]
And I want to know, within the 24 elements, which place the element is located which contains
//*[contains(text(), '${companyname}')]
Hoping someone can help!
Edit
This does not work:
Element should be visible ${item}//*[contains(text(), 'BargainsKing')]
And that's because:
Element with locator '<selenium.webdriver.remote.webelement.WebElement (session="4b40581d8835aac628e3a2032e355ee5", element="663438f7-76eb-4801-b255-021a865035dd")>//*[contains(text(), 'BargainsKing')]' not found.
Edit
I found the
${item.get_attribute('innerHTML')}
Now my next/final question is, can I look up an xpath within this innerHTML?
A solution is to count the number of elements and then get a FOR to cycle all elements
${count} Get Element Count XmlLocatorForAllElements
FOR ${i} IN RANGE 1 ${count}
${tmpElement} Get Element Count XmlLocator[${i}]/WithCompany
IF ${tmpElement} > ${0}
#element found
END
END
Could you please provide more detail about the selectors?
For now, I think you should try this:
You can check in the selector if there are any incremental values
if not then add a counter for each row
for selecting a specific column you can either go with the counter or the company name in Xpath

XPATH Last element with certain class

I have a date picker on my website,
It contains a list of elements for each week
and then those include 7 elements for each day
2930311234
Now I'm trying to xpath find the last button with class "is-selected"
And I'd also like to go trough each week since I want the last possible date ( "is-selected" means avaible)
I've tried
.//div[#'available-dates-calendar']//table/?[last()='True']//button[last()='True']
But that gave me the first element...
For the last() condition to work, I think that you would have to use the spy to create a XPath query that finds all buttons.
When such a query is found, then you can use the last() condition to find the last in the list of items found.
Hope this helps.
I believe you can use the [-1] identifier to grab the last element. So, instead of [last()='True'], use [-1].

Why bson_iter_type is 0x27,0x17?

I used the bson_iter_type() to get the type of iter. But the results (0x27, 0x17,0x1a,0x1b) are not listed in the official document mongodb-api-document. Why?
After bson_iter_init (&iter, my_bson_doc), iter does not point at the first element, but something ahead of the first element. After bson_iter_init (&iter, my_bson_doc) and bson_iter_next (&iter), iter will point at the first element if there are at least one element in bson. So, my problem stems from that the return of bson_iter_type() is not the type of the first element, but other things.
Now, bson_iter_next (&iter) is called to make sure iter point at the first element before bson_iter_type(). My problem is solved.

Prototype $$ returns array, should return one element like $

When using the dollar-dollar-function in prototype I alway get an array of elements back, instead of just one element with the dollar-function. How can I combine the power of CSS-selectors of $$ but still get only one element back?
Changing the structure of the source is not possible, so I can't just select it with the id. It needs to get selected with CSS, but should just return one element.
You can also do
$$('.foo').first()
It looks cleaner than $$('.foo')[0] for my taste :)
It does not make sense to return a single element when selecting by class name because potentially there could be many elements in the DOM that have this class. So you could always use the first element of the returned array if you are sure that it will be unique.
$$('.foo')[0]

Resources