What should I use to Click in webDriver

267 views
Skip to first unread message

vikas jain

unread,
Aug 22, 2012, 10:51:20 PM8/22/12
to seleniu...@googlegroups.com
I have 3 links whose HTML is given below. What should I write to click them.
The text on Links are a) Users  b) >User Groups c) User DC/Distributor/Account Assignments.
I am using webdriver in java. I am new to webdriver so forgive me if there is very simple solution to it.


<div id="ext-comp-1196" style="padding-bottom: 25px;">

<div class="ds-navlist-item x-view-over">
<h3>Users</h3>
<p>Allows you to manage Users</p>
</div>

<div class="ds-navlist-item x-view-over">
<h3>User Groups</h3>
<p>Allows you to manage User Groups</p>
</div>

<div class="ds-navlist-item x-view-over">
<h3>User DC/Distributor/Account Assignments</h3>
<p>Allows you to manage the Distribution Centers, Distributors and Accounts assigned to Users</p>
</div>

</div>


Shaba K

unread,
Aug 23, 2012, 6:02:54 AM8/23/12
to seleniu...@googlegroups.com
You can write 

driver.linktext("Users").click();


please google before posting it .. a mere googling can solve your problem

cheers,
s




--
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/-/Vbcj5ybZQasJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

vikas jain

unread,
Aug 23, 2012, 9:21:33 AM8/23/12
to seleniu...@googlegroups.com
I tried both these but none of that work .
a) driver.findElement(By.linkText("Users"));
b) driver.findElement(By.partialLinkText("Users"));

None of them is working , it gives error as
"org.openqa.selenium.NoSuchElementException: Unable to locate element:
{"method":"link text","selector":"Users"}"

org.openqa.selenium.NoSuchElementException: Unable to locate element:
{"method":"partial link text","selector":"Users"}

Peter Gale

unread,
Aug 23, 2012, 9:25:00 AM8/23/12
to Selenium Users
The 3 items you are referring to are not links, they are headers. Searching for link test won't work.

> Date: Thu, 23 Aug 2012 09:21:33 -0400
> Subject: Re: [selenium-users] What should I use to Click in webDriver
> From: vick...@gmail.com
> To: seleniu...@googlegroups.com

Krishnan Mahadevan

unread,
Aug 23, 2012, 9:31:17 AM8/23/12
to seleniu...@googlegroups.com
You are trying to find links, but it looks like based on the html snippet you shared, everything is within a <div> tag

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

vikas jain

unread,
Aug 23, 2012, 9:54:32 AM8/23/12
to seleniu...@googlegroups.com
I second that ... So what should I be writing to click them ??

Peter Gale

unread,
Aug 23, 2012, 10:08:21 AM8/23/12
to Selenium Users
There's nothing in the html that seems worth clicking on.

You need to determine what you want your test to do, then try to implement that yourself.

If you get stuck we might help, but we can tell you what test you need to write.

> Date: Thu, 23 Aug 2012 09:54:32 -0400

> Subject: Re: [selenium-users] What should I use to Click in webDriver
> From: vick...@gmail.com
> To: seleniu...@googlegroups.com
>

vikas jain

unread,
Aug 23, 2012, 10:38:16 AM8/23/12
to seleniu...@googlegroups.com
Do you think "<div class="ds-navlist-item x-view-over">" this would
be clicking it ?
or can we write native Xpath like "/html/div/div/..." and click that ???

Peter Gale

unread,
Aug 23, 2012, 10:40:36 AM8/23/12
to Selenium Users
What are you expecting clicking on the div to achieve?

> Date: Thu, 23 Aug 2012 10:38:16 -0400

Vikas

unread,
Aug 23, 2012, 11:07:34 AM8/23/12
to seleniu...@googlegroups.com, Selenium Users
To reach on other page.. 

Sent from my iPhone

Shaba K

unread,
Aug 23, 2012, 11:58:08 AM8/23/12
to seleniu...@googlegroups.com
Not use how you would reach there as there is no link or any object 

May be am not seeing with the html

cheers,
s

Mike Riley

unread,
Aug 23, 2012, 4:50:51 PM8/23/12
to seleniu...@googlegroups.com
There must be something in the class for those div tags that makes them clickable somehow.

You could use this XPath for Users:

"//div/h3[text()='Users']"

However, that would click on the h3 tag and not the div.  To click on the div try this:

"//div/h3[text()='Users']/../.."

I think you need both of the "/..", but maybe only one.  It's been a while since I did that.

Mike

vikas jain

unread,
Aug 23, 2012, 7:10:22 PM8/23/12
to seleniu...@googlegroups.com
Thanks So much Mike, it worked .. Thanks everyone who responded..

I am still getting used to webdriver... Thanks.
> https://groups.google.com/d/msg/selenium-users/-/9JkgTSx6QxEJ.

Mike Riley

unread,
Aug 24, 2012, 8:49:37 PM8/24/12
to seleniu...@googlegroups.com
You are welcome.  I had a similar thing where there was an h3 tag and so I was reminded of it when I saw your HTML.  That is why it is so important to show us the HTML your code is interacting with.

Mike
Message has been deleted

Ashish Juyal

unread,
Aug 27, 2012, 6:02:50 AM8/27/12
to seleniu...@googlegroups.com
Hi 
    I am trying to click a div ,here's the code
<td class="ui-pg-button ui-corner-all" title="Delete Item"><div class="ui-pg-div"><span class="ui-icon ui-icon-trash"></span>Delete</div></td>
I failed to click the div.

Here my code

WebElement elements =driver.findElement(By.xpath("//*[@id='ItemMasterPager_left']/table/tbody/tr/td[1]/div[contains(text(),'Delete')]"));
       
        
       
        Actions moveTo = new Actions(driver);
        moveTo.moveToElement(elements).click().build().perform();


Any help will be appreciated


Thanks in advance 
Ashish Juyal
Reply all
Reply to author
Forward
0 new messages