RE: [selenium-users] Unable to click Span element from selenium code

9,735 views
Skip to first unread message

Peter Gale

unread,
Aug 12, 2012, 8:49:16 AM8/12/12
to Selenium Users
In WebDriver I would XPath of //*[@id="ext-gen247" .. however that translates to Selenium RC (?) code.

But what do you mean by"'it's not working"? There's no indication in the snippet that you've provided that anything should trigger from clicking on the element.


Date: Sat, 11 Aug 2012 21:57:27 -0700
From: vick...@gmail.com
To: seleniu...@googlegroups.com
Subject: [selenium-users] Unable to click Span element from selenium code

I have to write selenium code for <span id="ext-gen247" class="x-menu-item-text">Logout</span>

I tried these options , but none of them seems to be working.

         // sel.click("ext-gen247");  // Today Button on Top left page
        //sel.click("//span[contains(text(),'Logout')]");
       //   sel.click("//span[@class='x-menu-item-text' and text() = 'Logout']");
        sel.click("text<span>=</span>Logout");    

But none of them seems to be working . Any ideas ? Many Thanks.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/IG5lL2hxG4wJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

vikas jain

unread,
Aug 12, 2012, 10:16:35 AM8/12/12
to seleniu...@googlegroups.com
Many Thanks Peter.
Basically I expect that when I click on this span element , it will go
to another page and I will have another selenium RC code to verify the
text on new page.

But my problem is when I am using any of these 4 options to click on
span element and go to new page , it says "element not found" ..

Peter Gale

unread,
Aug 12, 2012, 10:37:41 AM8/12/12
to Selenium Users
There's no 'onclick' even for this element, so I still don't know why you expect clicking on this particular element should trigger anything. It may be that the even t triggers of some other element/below this one.

Best show us the html of the page you are looking at.

Otherwise, I'm not used to the style of selectors you're using, so I'm not sure if  "sel.click('ext-gen247');" is looking for an element with a name of "ext-gen247" rather than an id of "ext-gen247".
To me it seems better to be explicit with such things. I think you can say "sel.click('id=ext-gen247');"



> > // sel.click("ext-gen247"); // Today Button on Top left page

> Date: Sun, 12 Aug 2012 10:16:35 -0400
> Subject: Re: [selenium-users] Unable to click Span element from selenium code
> From: vick...@gmail.com
> To: seleniu...@googlegroups.com

vikas jain

unread,
Aug 12, 2012, 1:08:13 PM8/12/12
to seleniu...@googlegroups.com
I see what you are saying that span is not clickable , I didn't know that.


I am writing complete HTML from that page section .


<li id="x-menu-el-ext-comp-1111" class="x-menu-list-item">
<a id="ext-comp-1111" class="x-menu-item" href="#" unselectable="on"
hidefocus="true">
<img id="ext-gen248" class="x-menu-item-icon " src="/images/s.gif">
<span id="ext-gen249" class="x-menu-item-text">Logout</span>
</a>
</li>

So, what should be the best approach to write selenium java code to
click on "Logout" .  because from UI , I can click "Logout" and I want
to automate that scenario.

Many Thanks.

Peter Gale

unread,
Aug 12, 2012, 1:14:57 PM8/12/12
to Selenium Users
Well, still assuming it's not just a simple locator syntax problem, which it doesn't seem to be, you need to determine what element trigger's the loading of the new page, and click on that with Selenium.

I would have suggested that it was the anchor <a> tag, but taht doesn't seem to have a new URL and it is odd that it has an "unselectable" attribute which is set to "on" - I've not seen this before, myself.

Either there's not not enough in this section of HTML to explain what is going on or there's some complexity in the way the linking works on this element that I at least don't understand. It would be worth speaking to the developers of the page to see if they can explain precisely whcih element you need to click on (with Selenium) that will trigger loading the new page.


Date: Sun, 12 Aug 2012 10:08:13 -0700
From: vick...@gmail.com
To: seleniu...@googlegroups.com
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/bglMg3-wQ3UJ.

anji prassana

unread,
Aug 13, 2012, 12:12:41 AM8/13/12
to seleniu...@googlegroups.com
>>So, what should be the best approach to write selenium java code to
>>click on "Logout" .  because from UI , I can click "Logout" and I want
>>to automate that scenario.
Seems to be the app. you are going to automate was implemented on Ext-Gwt. where element ids are dynamic and were subject to change for each session.So, first thing is dont write your script with 'id' properties as these are not consistent across the sessions. Go woth 'xpath' to locate elements unless they are static.Also, i would recommend you to migrate to webdriver rathert than trying to automate with selenium RC.Because, As you move on you may find so many difficulties with selenium RC while automating the GXT applications;I had worked on GXT app. earlier and as per my exp. i am suuggesting webdriver is the best fit for these applications.
 
To click on Logout button you can go with.
selenium.click("xpath="//span[text()='Logout']");
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/bglMg3-wQ3UJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Thanks&Regards
Anjaneyulu P
"The way you see the things is the way to think and is the way you react upon!!"

vikas jain

unread,
Aug 13, 2012, 10:35:16 PM8/13/12
to seleniu...@googlegroups.com
Anji , Thank you so much. Do you know any demo , material , steps to
download jar and quickly go through basics of web driver and start
working on it.

vikas jain

unread,
Aug 13, 2012, 11:26:59 PM8/13/12
to seleniu...@googlegroups.com
Anji , I started using webdriver. I have this html code in web page.
<button id="ext-gen31" class="x-btn-text" type="button">User,
Intervolve</button>

I wrote this webdriver code for this.
d1.findElement(By.name("User, Intervolve")).click();

But I got error. Do you see something missing over here . Many Thanks.

anji prassana

unread,
Aug 14, 2012, 12:23:29 AM8/14/12
to seleniu...@googlegroups.com
Hey Vikas,
   By.name() function searches for the given name in the 'name' attribute of the element. But, for your element there is no 'name' attribute exists. If you wanna match with the button text, then you go with xath and your xpath should be..
 //button(text()='User,Intervolve')
 
So, driver.findElement(By.xpath("//button[text()='User,Intervolve']");

anji prassana

unread,
Aug 14, 2012, 12:25:16 AM8/14/12
to seleniu...@googlegroups.com
 There is no better place than seleniumhq.org for all the needs you mention....

vikas jain

unread,
Aug 14, 2012, 8:23:12 PM8/14/12
to seleniu...@googlegroups.com
Hey Anji,

================================================================================
This is the error which I got when I used
driver.findElement(By.xpath("//button[text()='User,Intervolve']");

Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException:
Unable to locate element:
{"method":"xpath","selector":"//button[text()='User,Intervolve']"}.


This is HTML code :- <em id="ext-gen239" class="x-btn-split" unselectable="on">
<button id="ext-gen31" class="x-btn-text" type="button">User,
Intervolve</button>
</em>

So, then I got the xpath via firepath :-
d1.findElement(By.xpath("//*[@id='ext-gen31']")).click(); , It worked
, but you told earlier that this web page uses EX-GWT where ID's will
change. So, what do you suggest ??

=============================================================================
I have many items in HTML code like this :-
<a id="ext-comp-1111" class="x-menu-item" href="#" unselectable="on"
hidefocus="true">
<img id="ext-gen248" class="x-menu-item-icon " src="/images/s.gif">
<span id="ext-gen249" class="x-menu-item-text">Logout</span>
</a>

what is the best alternative to use . Right now I am using
d1.findElement(By.xpath("//*[@id='ext-comp-1111']")).click(); , but
again same problem will come that ID's will change.

Many Thanks,

anji prassana

unread,
Aug 14, 2012, 11:22:58 PM8/14/12
to seleniu...@googlegroups.com
Add some sleep to let the element visible.Also, try with this xpath as well...
driver.findElement(By.xpath("//button[contains(text(),'Intervolve']"));

vikas jain

unread,
Aug 15, 2012, 11:10:50 PM8/15/12
to seleniu...@googlegroups.com
driver.findElement(By.xpath("//button[contains(text(),'Intervolve']"));
worked .. many thanks..
I am new to webdriver ,I might ask silly questions ....

vikas jain

unread,
Aug 15, 2012, 11:34:32 PM8/15/12
to seleniu...@googlegroups.com
I have 1 issue .
This is my HTML.

<em class="x-btn-arrow" unselectable="on">
<button id="ext-gen20" class=" x-btn-text ds-module-today-hover" type="button">
<b> Today</b>
</button>
</em>


I tried these things :-
1) d1.findElement(By.xpath("//button[contains(text(),'Today')]")).click();
//actually there is one more item whose name is "Today Module
Settings", so it clicked the other one.
2) d1.findElement(By.xpath("//button[text()= ' Today')]")).click();
3) d1.findElement(By.className(" x-btn-text ds-module-today-hover")).click();
4) d1.findElement(By.xpath("//className[contains(text(),'ds-module-today-hover')]")).click();
But 2 or 3 or 4 didn't work. Any suggestions ?

anji prassana

unread,
Aug 15, 2012, 11:45:13 PM8/15/12
to seleniu...@googlegroups.com
Try any one of these xpaths.
 
//em[@class='x-btn-arrow']/button[text()='Today']
   [or]
//button[text()='Today']
 
Here what you need to notice is: contains() function will match the given text across the whole elements text.Whereas, text() function alone [without including in contains() function as we did earlier] will match the element text exactly.So, it won't match the other elements which contain 'Today' as in "Today Module
Settings".It will match only the elemets whose text is exactly 'Today' but not 'Welcome Today','Today mood' etc..

vikas jain

unread,
Aug 16, 2012, 7:06:31 AM8/16/12
to seleniu...@googlegroups.com
I tried :-

a) //button[text()='Today'] or //button[text()=' Today'] //
did not work
b) //em[@class='x-btn-arrow']/button[text()='Today'] or
//em[@class='x-btn-arrow']/button[text()=' Today'] // did not work
c) d1.findElement(By.xpath("//em[@class='x-btn-arrow']/button[contains(text(),'Today')]"));
// did not work

HTML is :-
<em class="x-btn-arrow" unselectable="on">
<button id="ext-gen20" class=" x-btn-text ds-module-today-hover"
type="button">
<b> Today</b>
</button>
</em>

I can not use
d1.findElement(By.xpath("//button[contains(text(),'Today')]")); //
because there is another button with text "Today More...." .

any ideas ??

mayankkumar patel

unread,
Feb 12, 2016, 1:11:03 AM2/12/16
to Selenium Users, anji...@yahoo.co.in
Thanks for specifying on ow to find Span Element
Reply all
Reply to author
Forward
0 new messages