CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Special selectors with Selenium Test

 



Chaoui005
Novice

Apr 21, 2016, 7:23 PM

Post #1 of 15 (5279 views)
Special selectors with Selenium Test Can't Post

Hello Perl's users!! Iam beginner in Perl and new in the forum. So my issue is : I would like to test some web page with differents browsers. I use for that Selenium with Perl also. I have for that this code enclosed here. My issue is that i cannot find ,with my test in pasted code here, one selector in particular from a Datagrid which is created by a css framework i used in my web pages; css framework named DevBuilder. So this selector have got a particular class name generated by DevBuilder. But this name, name of the class of this selector IS COMMON to several others buttons in the Datagrid (table). When i have to get it , in test, it checks an other button ! Consequently, how can i do to call this selector in particular and use it (it's a button in a table , a Datagrid from DevBuilder) . I think i have to use a function perl but iam not sure. How can i do ? Thanks !!



Code
    $elem =  $driver->find_element('//div[@class="dx-widget dx-button-has-icon dx-button dx-button-normal"]'); 
$driver->mouse_move_to_location(element => $elem);
$driver->click('LEFT')


My web code related found with the chrome inspector is :<div class="dx-widget dx-button-has-icon dx-button dx-button-normal" tabindex="0" onclick="void(0)" role="button" aria-label="preferences">


Thanks . PS: i can give more code if necessary
Smile


Zhris
Enthusiast

Apr 21, 2016, 10:53 PM

Post #2 of 15 (5276 views)
Re: [Chaoui005] Special selectors with Selenium Test [In reply to] Can't Post

You are using Selenium::Remote::Driver::find_element's default FINDER, xpath ( http://www.w3schools.com/xsl/xpath_syntax.asp ). Modify your xpath query appropriately. Assuming its the only button in a table cell:


Code
//td/div[@class="dx-widget dx-button-has-icon dx-button dx-button-normal"]


If this is still too weak, strengthen it by identifying the table cells position using predicates, there is always a way to uniquely query a specific element via xpath.

Chris


(This post was edited by Zhris on Apr 21, 2016, 11:10 PM)


Chaoui005
Novice

Apr 22, 2016, 6:44 AM

Post #3 of 15 (5263 views)
Re: [Zhris] Special selectors with Selenium Test [In reply to] Can't Post

Sorry . I used this xpath after but i forgot to add it in my code here . I did exactly like that.
Unsure
I took all the morning to search a solution even with your approach. But still doesn't work

Using predicates. What do you mean by this ?

The "problem" is that my css builder, DevBuilder, makes itself selectors and attributes with their own names. And so, even with xpath , as i did, it doesn't work cause it refers to severals buttons with the same class and not only one. And we cannot modify css Builder page generated.

You will tell me: how this DevBuilder organizes all buttons also? It uses an attribute named 'tableindex' . tableindex =0 for example as it written in my firt post. But i think ,cause i didn't find the way, we can't use it with Selenium::Remote::Driver.

But it could be necessarily possible to test them . I thought to create a function with Perl but i don't know where to begin. My level in Perl is still too poor , i am a beginner. Blush

And many thanks for your time ! Smile


(This post was edited by Chaoui005 on Apr 22, 2016, 6:45 AM)


Zhris
Enthusiast

Apr 22, 2016, 3:42 PM

Post #4 of 15 (5254 views)
Re: [Chaoui005] Special selectors with Selenium Test [In reply to] Can't Post

Have a look at the link I posted in my previous post.


Quote
Predicates are used to find a specific node or a node that contains a specific value


You haven't provided enough specific information for us to modify your xpath query to suit your exact need. For example, if the button you want to click is in the last row of the first table:


Code
//table[1]/tr[last()]//div ...


Chris


Chaoui005
Novice

Apr 25, 2016, 1:10 AM

Post #5 of 15 (5226 views)
Re: [Zhris] Special selectors with Selenium Test [In reply to] Can't Post

It's ok . I finally got it with your xpath method. But i have still one last problem.

In file attached here, i would like to get attribute from class in a xpath too. Mine is highlighted in blue in file. But as you can see i have 2 tables and one table is in one other table. How can i do in this case.

Thanks !


(This post was edited by Chaoui005 on Apr 25, 2016, 8:29 AM)
Attachments: help2.png (162 KB)


Zhris
Enthusiast

Apr 25, 2016, 8:19 AM

Post #6 of 15 (5212 views)
Re: [Chaoui005] Special selectors with Selenium Test [In reply to] Can't Post

No file attached.

You can select a table within a table broadly using:


Code
//table//table


Chris


Chaoui005
Novice

Apr 25, 2016, 8:29 AM

Post #7 of 15 (5207 views)
Re: [Zhris] Special selectors with Selenium Test [In reply to] Can't Post

I added file right now.

I already know this method


Zhris
Enthusiast

Apr 25, 2016, 8:49 AM

Post #8 of 15 (5204 views)
Re: [Chaoui005] Special selectors with Selenium Test [In reply to] Can't Post

Thanks.

The element highlighted in blue appears to have a unique class, therefore you can match it directly. If you want one of its attributes, match the element, followed by /@attribute.

If you are still having trouble, attach your whole html document, provide the line number of the element you want to match, explain whether you want the node or the value of an attribute, accompanied with example output where possible.

Chris


(This post was edited by Zhris on Apr 25, 2016, 8:51 AM)


Chaoui005
Novice

Apr 26, 2016, 6:29 AM

Post #9 of 15 (5190 views)
Re: [Zhris] Special selectors with Selenium Test [In reply to] Can't Post

I tried your method but it's possible i didn't write it well.
Then i would like to get "button(checkbox exactly)" from my css framework , which is in a table . And i would like after that to get an other checkbox with the same class which is an other table.

I follow u files so . First is checkbox i got with following xpath:
$elem = $driver->find_element('//table[1]//tr//td//div[@class="dx-select-checkbox dx-datagrid-checkbox-size dx-widget dx-checkbox"]');

I think i was just lucky to get it cause there is only one table like that .

And the second i would like to get i did like that but it doesn't work:
$elem = $driver->find_element('//div//table//tr[3]//td//div[@class="dx-select-checkbox dx-datagrid-checkbox-size dx-widget dx-checkbox"]');

so in 1st file first checkbox i got and in the second in blue the second checkbox i would like to get.


Thanks again Chris !!

PS: i added a third file where you can see them
Attachments: help3.png (171 KB)
  help4.png (179 KB)
  help5.png (15.3 KB)


Zhris
Enthusiast

Apr 27, 2016, 10:49 AM

Post #10 of 15 (5161 views)
Re: [Chaoui005] Special selectors with Selenium Test [In reply to] Can't Post

I really need the document in a text format, not a screenshot. This way I can perform searches, run my own xpath queries, and provide you with much more useful answers.

Chris


(This post was edited by Zhris on Apr 27, 2016, 10:49 AM)


Chaoui005
Novice

Apr 28, 2016, 12:36 AM

Post #11 of 15 (5150 views)
Re: [Zhris] Special selectors with Selenium Test [In reply to] Can't Post

I am working in local . But i can give you my file .

https://paste.fedoraproject.org/360583/18303571/

And password is 'bibi'


(This post was edited by Chaoui005 on Apr 28, 2016, 1:00 AM)


Zhris
Enthusiast

Apr 28, 2016, 3:33 PM

Post #12 of 15 (5134 views)
Re: [Chaoui005] Special selectors with Selenium Test [In reply to] Can't Post

I meant the html document.

Chris


Chaoui005
Novice

Apr 29, 2016, 2:29 AM

Post #13 of 15 (5117 views)
Re: [Zhris] Special selectors with Selenium Test [In reply to] Can't Post

I think it would be difficult as you can see with the following file ( i use layout ). I have many files and frameworks used
Attachments: help6.png (24.5 KB)


Zhris
Enthusiast

Apr 29, 2016, 4:52 PM

Post #14 of 15 (5101 views)
Re: [Chaoui005] Special selectors with Selenium Test [In reply to] Can't Post

The rendered html, you attached screenshots of it. Navigate to the page then view and copy its source. Otherwise use a program such as curl or wget.

Alternatively provide a short, complete, representative example, from which you should be able to directly apply suggested xpath queries to your actual html document.

Chris


Chaoui005
Novice

May 4, 2016, 3:50 AM

Post #15 of 15 (5047 views)
Re: [Zhris] Special selectors with Selenium Test [In reply to] Can't Post

Hi ! Thanks a lot Chris for your help. I was sick. I couldn't answer before!
COncerning my problem i tried differently with an other button.

I just would like to thank you for your patience !
It's very reassuring to know we can count on people like u when we begin Perl

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives