On Sun, Sep 28, 2014 at 8:21 PM, Ahmed Neinae <
ahmed....@gmail.com> wrote:
> On Fri, Sep 19, 2014 at 8:50 AM, Andreas Tolfsen <
a...@mozilla.com> wrote:
>>
>> ↪ Ahmed Neinae <
ahmed....@gmail.com>:
>> > I am using selenium 2.42.2 running my script on FF Browser. I am trying
>> > to identify some objects in my application so I can perform some actions
>> > like click or sendKeys, however these objects are HTML5 canvas objects
>> > and they all have the same id, name and xpath as well. I wonder how can
>> > I find a unique identification for this object?
>>
>> find_elements returns a collection of web elements. Pseudo code to get
>> the element reference of the third canvas:
>>
>> cs = find_elements_by_tag_name("canvas")
>> canvas = cs[2]
>>
>
> Thanks much for the answer, Can you please explain little more??
I'm not sure my answer could be made much clearer, but perhaps I'm
misunderstanding your problem.
You say you have three canvas elements in your document as such:
<canvas>…</canvas>
<canvas>…</canvas>
<canvas>…</canvas>
Because neither of them has a unique ID identifier, you need a way to
access one of them directly. My code above retrieves element
references to all three and access the third element of the sequence.
Using a CSS selector you could also select the third one directly:
third_el = find_elements_by_css("canvas:nth-child(3)")