byCoder
byCoder

Reputation: 9184

Watir - get image without any property

I have such structure:

<div id="recaptcha_image" style="width: 300px; height: 57px;">
  <img style="display:block;" alt="Проверка по слову reCAPTCHA" height="57" width="300" src="https://www.google.com/recaptcha/api/image?c=03AHJ_VusSUxF0IYURRcVTVTjJJnUk92j-hXYsuwqvu0m5tvKFzAnwvrHlz-j_Gfqg-sUrHLj3D2DrUYNNg4uvr2BNgZqlK5vpJUJVYkkWo36I4RRmRGkYZru5kBYhzPCCn49KlH6wW_iLw6vIzv7vnhpu6ndqxb-9SkIRrVYyBwN39kg18Lov7Hc">
</div>

How can I, using watir, save this image (it is recaptcha)? Because I can't access it via name, id, or class.... only via parent id, but how?

Like this:

@browsers.image(:id=> '//recaptcha_image').save("cap.jpg")

So how to access image with no properties, and dynamic path?

Upvotes: 1

Views: 502

Answers (1)

Justin Ko
Justin Ko

Reputation: 46836

If you know the parent, you can access the parent and then get the first image (since there is only one image in the div tag). So you can get the image element by:

@browsers.div(:id => 'recaptcha_image').image

And to save the image:

@browsers.div(:id => 'recaptcha_image').image.save("cap.jpg")

Upvotes: 1

Related Questions