开发者

Is it possible to click on text that is not a link using watir

i am using watir in the firefox browser

I am looking for a way to click on text that is not a link. I have verified that the text exists on the website using

b.text.include? "Tasks"

I've tried several different ways to click on this text, but all have been unsuccessful, thus far i have tried

b.link(:text, "Tasks").click
b.text.click "Tasks"
b.text(:text, "Tasks").click

is there a 开发者_StackOverflowway to click on this text using watir? any help would be greatly appreciated


If clicking on this text that is not a link causes something to happen, then it is likely that there is an container element that encapsulates the text which is 'wired' to execute some specific javascript when a particular event (like onMouseDown or onClick) is detected. A large number of element types are possible (span, div, table cell, just to name a few) depending on how the developer designed the page.

Since multiple containers can be nested (ala a geek version of Russian Dolls) it's important to know or figure out which one will trigger the client side code when it is clicked. To do this you need to look at the HTML for the page or use a developer tool (all modern browsers have them) to examine the DOM in the vicinity of the text that is 'clickable'

To give you a better answer that is anything but general advice, We Need To See The HTML for that part of the page in order to be able to tell what kind of element this is, and suggest the proper (how, what) values and element type that would be needed in order to create the line of code that would click on the element, or fire the needed event.

Until you can provide that additional detail (EDIT your question to add the information to it) your question and hence the answers as well, will all suffer from GIGO syndrome


If the text you're trying to click is contained in a paragraph or span tag, could possibly select it this way? You could also use the :id selector if the wrapping tag had an identifier. Hopefully that works.

I don't know your use-case, but if the text could be a link, you could use event.preventDefault on the click event to keep it from doing anything.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜