简体   繁体   English

Javascript-尝试定位图像

[英]Javascript - trying to locate an image

I am not expert in javascript, so, excuse my lack of knowledge. 我不是javascript方面的专家,所以请原谅我缺乏知识。

I am trying to interact with an image on a page on the web, to create some automation. 我正在尝试与网络页面上的图像进行交互,以实现某种自动化。

I need to click on that image using javascript, from a script. 我需要使用JavaScript从脚本中单击该图像。

I did everything to discover how to access that image and no success at all. 我竭尽全力发现如何访问该映像,但完全没有成功。 The image is not responding to anything. 图像没有任何反应。 I suppose I am not reaching the right object. 我想我没有达到正确的目标。

Trying to discover the object, I created a very simple script, that will scale every image on that page, to see at least if I can reach all img object. 为了发现对象,我创建了一个非常简单的脚本,该脚本将缩放该页面上的每个图像,以至少查看我是否可以访问所有img对象。

This is the script 这是脚本

for (i=0;i<=100;i++) {
document.image[i].width.value = '300';
}

No changes at all. 完全没有变化。

Is the script correct? 脚本正确吗? is that anything that may be preventing the image to respond from external scripts? 是什么可能阻止图像从外部脚本响应?

Any clues? 有什么线索吗? thanks. 谢谢。

___ EDIT ___编辑

the image I need to click is declared like this: 我需要单击的图像声明如下:

 <div class="leaderboard-text">
          <span id="addon-add-language-button"><image class="ajaxListAddButtonEnabled" listId="localizationList" src="/itc/images/blue-add-language-button.png"><image class="ajaxListAddButtonDisabled" listId="localizationList" style="display:none;" src="/itc/images/blue-add-language-button-disabled.png"></span>
        </div>

There is no document.image , there is document.images 没有document.image ,有document.images

for (var i=0, l=document.images.length; i<l; i++) {
  var ing = document.images[i];
  img.width = 300; // but why do you want all images to be equal width?
}

You missed an 's' in images and some other things. 您错过了图像和其他一些东西的“ s”。

for (i=0, lughez = document.images.length; i<lughez ; i++) {
    document.images[i].width= '300';
}

but if the image has an id you could do: 但是,如果图像具有ID,则可以执行以下操作:

document.getElementById('id').click()

to click your image where 'id' is the id you are using 单击图像,其中“ id”是您使用的ID

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

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