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!