1 Replies - 330 Views - Last Post: 19 December 2013 - 03:18 AM Rate Topic: -----

#1 rdbindia  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-December 13

Using Xpath in java for clicking all the buttons on the page

Posted 19 December 2013 - 02:54 AM

Hey i am implementing selenium using eclipse & using xpath to click a button on my webpage,but i manage to click only a single button on the page,if i try to use the code for other buttons on the page it does not happen.Secondly when i scroll down to the specified button into the code then only the button gets clicked or else the button just scrolls down and comes to the top without clicking it.
The Xpath i get using the Selenium IDE is as follows:
xpath=(//a[contains(text(),'Add to cart')])[5] xpath:link
//a[contains(@href, '/?add-to-cart=85')] xpath:href
//li[5]/div/a xpath:position
I am using the following code to click the button:
 
WebElement ele = driver.findElement(By.xpath("//a[(@href= '/ecommerce/?add-to-cart=85')]"));
ele.click();



Is This A Good Question/Topic? 0
  • +

Replies To: Using Xpath in java for clicking all the buttons on the page

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2812
  • View blog
  • Posts: 11,902
  • Joined: 20-September 08

Re: Using Xpath in java for clicking all the buttons on the page

Posted 19 December 2013 - 03:18 AM

Surely you should be using something more like http://selenium.goog...va.lang.String)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1