How to call the custom tags?

38 views
Skip to first unread message

rajagopalan madasami

unread,
May 28, 2019, 1:15:05 AM5/28/19
to Watir General
Hi,

I have a custom tag named `lf-select`

Can't I call in WATIR like

b.lf_select()

Or something like that? Or Is there anyway?

Justin Ko

unread,
May 28, 2019, 9:26:52 AM5/28/19
to Watir General
For custom elements, you will need to use the #element method:

b.element(tag_name: 'lf-select')

Justin

rajagopalan madasami

unread,
May 28, 2019, 9:40:22 AM5/28/19
to Watir General
wow, that's beautiful, thanks.

rajagopalan madasami

unread,
May 28, 2019, 9:45:37 AM5/28/19
to Watir General
Justin,

Can you please help me to write this code in watir?

b.span(xpath: "//label[@title='Subject']/following-sibling::div/lf-select/div/span").click


I have tried this

b
.label(title: 'Subject').following_sibling.element(tag_name: 'lf-select').div.span.click

But it's not working.

Can you help me here?

On Tuesday, 28 May 2019 18:56:52 UTC+5:30, Justin Ko wrote:

Titus Fortner

unread,
May 28, 2019, 10:22:13 AM5/28/19
to Watir General
I'd need to see the underlying html to know for sure, but it looks like you want to specify the tag name of the following sibling `following_sibling(tag_name: 'div')`

rajagopalan madasami

unread,
May 28, 2019, 11:58:18 AM5/28/19
to watir-...@googlegroups.com
I think you are right. Yes, I should have done that way. Let me try tomorrow as soon as I reach office and let you know.

--
--
Before posting, please read https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
In short: search before you ask, be nice.
 
watir-...@googlegroups.com
http://groups.google.com/group/watir-general
watir-genera...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-genera...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/watir-general/792fb46a-fcaf-44ef-a502-f11fa5d223fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

rajagopalan madasami

unread,
May 29, 2019, 3:10:58 AM5/29/19
to Watir General
I have written the following code

b.label(title: 'Subject').following_sibling(tag_name: 'div').element(tag_name: 'lf-select').div.span.click



It throws this error of element not present

But this one

b
.label(title: 'Subject').following_sibling(tag_name: 'div').element(tag_name: 'lf-select').div.span.click



works fine.

rajagopalan madasami

unread,
May 29, 2019, 3:21:27 AM5/29/19
to Watir General
And I have printed the xpath WATIR is creating, here it is

".//*[local-name()='i'][contains(concat(' ', @class, ' '), ' fa-spin ')]"
".//*[local-name()='label'][@title='Subject']"
"./following-sibling::*[local-name()='div'][1]"
".//*[local-name()='lf-select']"
".//*[local-name()='div']"
".//*[local-name()='span']"



On Tuesday, 28 May 2019 19:52:13 UTC+5:30, Titus Fortner wrote:

rajagopalan madasami

unread,
May 29, 2019, 3:22:26 AM5/29/19
to Watir General
Plese reject the last mail in which one extra line was added, WATIR is creating the following xpath

".//*[local-name()='label'][@title='Subject']"
"./following-sibling::*[local-name()='div'][1]"
".//*[local-name()='lf-select']"
".//*[local-name()='div']"
".//*[local-name()='span']"



On Tuesday, 28 May 2019 19:52:13 UTC+5:30, Titus Fortner wrote:

Justin Ko

unread,
May 29, 2019, 11:29:59 AM5/29/19
to Watir General
Which is the working one? The code appears to be the same for both the working and not working one.

I assume that the working one is the original :xpath locator you were trying to convert. If that's the case, I would guess you are running into how Watir returns the first match of each individual method call rather than the first matching the entire series of chained methods.

For example, your Watir code should work for:

<html>
 
<body>
   
<label title="Subject">Label</label>
   
<div><lf-select><div><span>Value</span></div></lf-select></div>
 
</body>
</html>

But it will not work for:

<html>
 
<body>
   
<label title="Subject">Label</label>
   
<div>another</div>
   
<div><lf-select><div><span>Value</span></div></lf-select></div>
 
</body>
</html>

Notice in the failed page that there is an extra div between the label and div containing lf-select. The code, label(title: 'Subject').following_sibling(tag_name: 'div'), finds the first sibling of the label, regardless of whether it contains the lf-select. In contrast, the :xpath locator does consider the div children and therefore ignores the first sibling.

Assuming you are in the second example, you will need to tell Watir more specifically which following sibling you need.

I suppose the closest representation to the XPath, would be to iterate over the siblings until you find the one with the lf-select:

browser.label(title: 'Subject').following_siblings(tag_name: 'div')
 
.find { |e| e.element(tag_name: 'lf-select').exists? }
 
.element(tag_name: 'lf-select').div.span.text

If you know the exact position of the sibling you could simplify this to:

browser.label(title: 'Subject').following_sibling(tag_name: 'div', index: 1).element(tag_name: 'lf-select').div.span.text

#following_sibling accepts the usual locators, so you could use whatever identifiable attributes it has.

Justin

rajagopalan madasami

unread,
May 30, 2019, 2:47:14 AM5/30/19
to Watir General
Hi, your code is not working for me. Here is the Html

rajagopalan madasami

unread,
May 30, 2019, 3:04:35 AM5/30/19
to Watir General
I think this one is pointing to some span which is hidden because this error was thrown


Uncaught exception: element located, but timed out after 30 seconds, waiting for #<Watir::Span: located: true; {:title=>"Subject", :tag_name=>"label"} --> {:tag_name=>"div", :adjacent=>:following} --> {:tag_name=>"lf-select"} --> {:tag_name=>"div"} --> {:tag_name=>"span"}> to be present

rajagopalan madasami

unread,
Jun 14, 2019, 1:16:37 AM6/14/19
to Watir General
JustinKo,

I have succeeded with following code

b.label(title: 'Visibility')
 
.following_sibling(tag_name: 'div')
 
.element(tag_name: 'lf-select')
 
.div
 
.span(class: 'ng-arrow-wrapper')
 
.click

rajagopalan madasami

unread,
Jun 14, 2019, 1:17:35 AM6/14/19
to Watir General
JustinKo,

following code works for

b.label(title: 'Subject')

 
.following_sibling(tag_name: 'div')
 
.element(tag_name: 'lf-select')
 
.div
 
.span(class: 'ng-arrow-wrapper')
 
.click
Reply all
Reply to author
Forward
0 new messages