简体   繁体   English

watir-webdriver单击图像

[英]watir-webdriver click on image

Folks, 伙计们,

I have an image with the following HTML code: 我有一个包含以下HTML代码的图像:

<div unselectable="on" class="x-grid-cell-inner x-unselectable" style="; text-align: right;" id="ext-gen1453">
<img alt=""src="data:image/gif;base64,FRFRFR/GFFFFFFFFFF==" class="x-action-col-icon x-action-col-0 folder-action-add folder-action" data-qtip="Add New Music File" id="ext-gen1300">

When I click on the image it should open a pop up so that I can add new music file, I tried a few things but I am not able to click on that image. 当我点击图像时,它应该打开一个弹出窗口以便我可以添加新的音乐文件,我尝试了一些东西,但我无法点击该图像。 Any suggestions? 有什么建议么?

Thanks a lot 非常感谢

You can click on it by the class or a partial match of the class. 您可以通过类或类的部分匹配来单击它。

@browser.image(:class=>/folder-action-add folder-action/).click

Here is a list of the identifiers you can use for watir , I think it's mostly the same for watir-webdriver. 这是一个可以用于watir标识符列表,我认为它对于watir-webdriver来说大致相同。

So far, you haven't got a consistent way of actually identifying the element. 到目前为止,您还没有一种实际识别元素的一致方法。 From what you've said in the comments, you've tried the 'text' attribute which doesn't exist, and the 'id' attribute which is auto generated and different every time. 根据您在评论中所说的内容,您已经尝试了不存在的'text'属性,以及每次都自动生成且不同的'id'属性。

You need to find a way of consistently identifying the element. 您需要找到一种始终识别元素的方法。 It's usually preferable to use a semantic class on the element to make styling and testing easier and less brittle. 通常最好在元素上使用语义类,以使样式和测试更容易,更不易碎。 You have a few classes declared, perhaps 'folder-action-add' expresses the intent of the button clearly? 你有一些声明的类,也许'folder-action-add'清楚地表达了按钮的意图? If not, you could add one such as 'add-music-file'. 如果没有,您可以添加一个例如'add-music-file'。

Then you should be able to use watir to select an element by it's class, I'm not familiar with the syntax but at a guess, @browser.image(:class => 'add-music-file') might do the job. 然后你应该能够使用watir按类来选择一个元素,我不熟悉语法但是猜测, @browser.image(:class => 'add-music-file')可能会完成这项工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM