!!

Welcome to Selenium Webdriver Forum

As a web user you can read and search through forum content. Once you have registered and signed you can post topics, post replies, set up watch lists, modify forum settings, and use private messaging.

Author Topic: How to click on this link  (Read 1038 times)

bulgakov_v

  • Web User
How to click on this link
« on: July 24, 2012, 05:42:52 PM »
I am using Python WebDriver.
I tried different ways to click on this:

<div class="add-listing ot_gt_advertise">
 <a href="http://www.foo.com/business-listings?tsrc=SP&campaignId=SP_header">
 <span>Add Your</span>
 FREE Listing
 </a>
</div>

for example:
driver.find_element_by_partial_link_text("Add Your").click()
returns
Message: u'Unable to locate element: {"method":"partial link text","selector":"Add Your"}'

djochen

  • Web User
Re: How to click on this link
« Reply #1 on: July 24, 2012, 05:43:10 PM »
Maybe try using XPath instead? Use the Selenium IDE to pinpoint the exact location of the element and then use its XPath

--------------------
Selenium Testing in the cloud

Tarun_K

  • Web User
Re: How to click on this link
« Reply #2 on: July 24, 2012, 05:43:47 PM »
Can you try this -


driver.find_element_by_xPath("//span[text()='Add Your']").click()

sorry I am not aware of python API but key is the locator -
"//span[text()='Add Your']"

--------------------
~ Tarun
Free Selenium Training

Selenium Webdriver

Re: How to click on this link
« Reply #2 on: July 24, 2012, 05:43:47 PM »

felix_ada

  • Web User
Re: How to click on this link
« Reply #3 on: July 24, 2012, 05:44:01 PM »
Span is not a link , Use xpth or css selector instead.

spicynudles

  • Web User
Re: How to click on this link
« Reply #4 on: July 24, 2012, 05:44:13 PM »
Tarun's tip should work. I would also recommend using FirePath to ease your work.
FirePath

It's a firefox addon and extension to Firebug. a great tool to assist in selenium test development.

--------------------
Real world software testing approach, issues and possible solutions.
http://www.softwaretestingconcepts.com

bulgakov_v

  • Web User
Re: How to click on this link
« Reply #5 on: July 24, 2012, 05:44:27 PM »
What is the difference between "Inspect element" and "Inspect in Firepath"? They look the same.

dlai

  • Web User
Re: How to click on this link
« Reply #6 on: July 24, 2012, 05:44:42 PM »
Personally I would in this case use Partial URL to identify the link. Problem about using text is some editor might want to change the wording and you'll have to update your code. Also if the page were to be localized in the future you'll have an annoying time making the tests cross language compatible. URL are less likely to change than the link text.

Also, if you're using Selenium 2 and a language that supports annotation. It's better to use @FindBy annotations and page objects for better script maintainability.

--------------------
David Lai
Sr. QA / Test Lead
www.carsdirect.com

rolandormrod82

  • Web User
Re: How to click on this link
« Reply #7 on: July 24, 2012, 05:44:56 PM »
Perhaps try a Css Selector?

Perhaps the below will work?

find_element_by_css_selector("div.add-listing a").click()

--------------------
Read my Advanced Selenium Webdriver Automation Blog
 
Roland Ormrod

 

Related Topics

  Subject / Started by Replies Last post
2 Replies
1123 Views
Last post July 25, 2012, 10:10:26 PM
by Lukasz_Morawski
1 Replies
772 Views
Last post April 09, 2012, 02:01:06 PM
by Daniel Wagner-Hall
6 Replies
1646 Views
Last post May 03, 2012, 10:03:31 PM
by jeevan
7 Replies
1641 Views
Last post May 17, 2012, 10:10:10 PM
by Daniel Wagner-Hall
1 Replies
644 Views
Last post July 24, 2012, 06:24:00 PM
by rolandormrod82
2 Replies
1626 Views
Last post July 25, 2012, 10:09:11 PM
by fmtjatt
4 Replies
1252 Views
Last post July 25, 2012, 10:11:18 PM
by fmtjatt