0

Folks,

My first time on Stack Overflow. Hope y'all can help ...

I'm trying to use Selenium to click on the 'Buy Now' button on an html page. Here's the HTML snippet:

</div>
    <a href="javascript:void(0)" class="buttonCheckout">Buy Now</a>
    <a href="#" class="buttonSoldout">Sold Out</a>
</div>

I used the Selenium IDE to get the correct Xpath locator but the click event always fails.

>> chk = "id('yui-gen2')/x:div[3]/x:div/x:a[1]"
=> "id('yui-gen2')/x:div[3]/x:div/x:a[1]"
>> @selenium.get_xpath_count(chk)
=> "1"

>> @selenium.click(chk)
**Error**

>> chk = "xpath = " + chk
=> "xpath = id('yui-gen2')/x:div[3]/x:div/x:a[1]"
>> @selenium.click(chk)
**Error**

The **Error** is:
selenium-client received failure from selenium server:
requested:
 cmd=click
 1=xpath = id('yui-gen2')/x:div[3]/x:div/x:a[1]
 sessionId=d4d6796b3c9749139621cd0cbcde80b2
received:
 "ERROR: Element xpath = id('yui-gen2')/x:div[3]/x:div/x:a[1] not found"
 called from C:/Ruby187/lib/ruby/1.8/timeout.rb:67:in `timeout'
 enium::CommandError: ERROR: Element xpath = id('yui-gen2')/x:div[3]/x:div/x:a[1] not  found

I've tried some of the other suggestions on the forum - @selenium.double_click(chk), @selenium.fire_event(chk, 'click') - but those give the same Element not found error.

I've also tried all kinds of permutations of the above, tried others Xpaths (chk = "//a[@class='buttonCheckout']", chk = "/descendant::a[@class='buttonCheckout']", chk = "//a[@href='javascript:void(0)']".

In all of these cases, I believe I have found the right locator since the get_xpath_count method works but click always fails.

Any suggestions here? Thanks in advance!

1
  • 1
    You haven't shown the complete XHTML document and thus there is no way for anyone to verify that the XPath expressions would select the desired node. Please edit your question and provide all the necessary information. Commented Oct 24, 2010 at 15:36

2 Answers 2

1

Error message "Element xpath = ... not found" clearly states the real problem - so double click and fire event won't help.

You may try to install Selenium IDE plugin of Firefox, start recording and click on "Buy Now" button. Selenium IDE will automatically find some way to locate element. Also, it usually suggests several locator variants in drop-down list.

Also, you may try to use XPather / XPath checker plugins to find and check suitable xpath locators variants.

Sign up to request clarification or add additional context in comments.

Comments

0

This is embarrassing but I figured it out ... the XPath locator was fine.

The issue was with the spaces in the statement:

chk = "xpath = " + chk

It should be:

chk = "xpath=" + chk

And then everything works nicely.

Newbies hah.

Thanks all.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.