开发者

How can I know what element is clicked in IE?

I'm automating IE with watir, and I want to know what html element(s) are clicked (selected). Can this be done using watir? win32ole? In a last chance, without ruby?

Something like:

Click a button -> button with id=213 an开发者_JAVA技巧d class=btn_class was clicked. 
Click a text field -> text field with id=123 and value=my_text was clicked.


Try one of the recorders, Selenium IDE for example.


I'm not sure if I completely understand either, but would a custom function like this work?

        def click(item, how, what)
           @browser.item(how, what).click
           puts "#{item} with #{how}->#{what} was clicked"
        end

        click("button", ":id", "awesome")

Edit: If you're attempting to identify page elements so that you can then use them in a Watir script, the Developer Toolbar is perfect for this application, much like Firebug for Firefox. http://www.microsoft.com/download/en/details.aspx?id=18359

Your comment to me & your response to Zeljko appear to contradict each other. If you want to use WATIR for this task, the code above will execute a mouse click and post the information to console. The only other way to get information is to locate the object in WATIR and fish for more details:

object = @browser.button(:name, /myButton/)
object.id
object.title
object.status
object.height, etc.

or

@browser.divs.each do |div|
    puts div.id, div.title
end


I'd recommend a strong look at the capabilities of the various developer tools, such as are provided with Chrome, Firefox, and IE. those are generally the best means to get this kind of information.

Watir is really about driving the browser, and getting info out of the DOM. it's not really setup to report on manual interactions with the browser.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜