I have been struggling with this all morning and was hoping to get some assistance.
I have this button on a webpage that pulls up a control panel that lets the user select which widgets to display. I'm trying to get this to fire using watir webdriver and firefox 9.0 but having no luck at all. I'm able to login to the site, get to the page that contains the button but just can't click the 'CHOOSE YOUR FEATURES' button.
<div class="personalizationButton">
<span class="personalizationStatus"></span>
<b class="widgetPanelLink neo-button button-white">
<span>CHOOSE YOUR FEATURES</span>
</b>
</div>`
I've been concentrating on using div class 'personalizationButton' but perhaps I need to point to that 'b class'? Just not sure how to format it. Here are some examples of what I have tried
$browser.div(:class, 'personalizationButton').when_present.click
$browser.button(:text => 'CHOOSE YOUR FEATURES').click
$browser.button(:div => 'personalizationButton').click
etc, etc... just not sure I'm getting the format right. I watch it get to the page, I see the 'CHOOSE YOUR FEATURES' button on the page, but it never clicks it. Usually I get an error like this depending on which version was used:
unable to locate element, using {:text=>"CHOOSE YOUR FEATURES", :tag_name=>"button"}
This is the version I think should work, When I try it I get no errors but see nothing happen in the browser either:
$browser.div(:class => "personalizationButton").click
I'm not seeing anything inherently clickable (with output) in the HTML. With the IRB output, it shows that it is finding the div, but there is no action when clicking it. The <b> element is just the "bold" style, so we shouldn't need to try that.
If you can access the span with text CHOOSE YOUR FEATURES, that should be your button.
$browser.span(:text => "CHOOSE YOUR FEATURES").click
. . i have tried doing the same thing with godaddy.com buy it did work.
on the main page there is a button labeled "Buy Now" using the code below
brow.div(:class => 'gdhp-domain-link gdhp-rounded-corners').span(:text => 'Buy Now').click
I was
Related
I'm trying to click on a button that contains the words "Add To Cart" using ruby/watir.
If I use
cart = browser.link(text: 'Add To Cart')
if cart.present?
cart.click
It works (item gets added to cart) but I get a element click intercepted: Element ... is not clickable at point (441, 20). Other element would receive the click: (Selenium::WebDriver::Error::ElementClickInterceptedError
I'm new to ruby/watir so any help would be greatly appreciated.
Try this code whether it works. If it's not working then as you have stated, even after the error, it works, So I assume we have to issue the click on the element which is overlaying the target element. So Paste the entire error message. The error message must contain the element which is actually obscuring.
require 'watir'
b = Watir::Browser.new
cart = browser.link(text: 'Add To Cart')
if cart.present?
b.wait_while { cart.obscured? }
cart.click
end
Update
Okay, there are other two ways you have to try.
One is to use JavaScript.
cart.click!
Or click the element which is overlaying your element.From your error the element is division with class attribute 'row'. If you have more detail about that element, you can locate that element by yourself. But now, with the given detail, I form the locator.
b.div(class: 'row').click
there are few ways you can figure what is going on
try looking around the element
check if watir sees more than one link, this should produce 1
browser.as(text: 'Add To Cart').count
then try to click every element if it has more than 1
browser.as(text: 'Add To Cart')[0].click
browser.as(text: 'Add To Cart')[1].click
or try to click its parent, link can be behind overlay
browser.a(text: 'Add To Cart').parent.click
then check if same can be acomplished by clicking parent element directly
browser.div(class: 'wishlist_cart_button').click
or you can try with different approach, find element by some other attribute
browser.a(href: /setCurrentId/).click
also maybe there is a parent element with id so you can find the cart button easier
browser.element(id: "asdf").a(text: "Add To Cart").click
browser.element(id: "asdf").as.last.click
if everything above fails, then click it with selenium, since watir is worried about click being intercepted
browser.driver.action.move_to(browser.a(text: 'Add To Cart').wd).click.perform
hope something helps :D
Ok, I'm trying to access an image stored in an image library which on click closes the image library pop up and inserts the image into the page.
The html for the image is;
<img src="/uploads/images/thumbs/10.png?504" alt="Find Us" width="140" onclick="$('#removeButton', window.opener.document).show();
$('#myImgId', window.opener.document).show();
$('#imageHeadingID', window.opener.document).val('13');
$('#myImgId', window.opener.document).attr('src', '/uploads/images/thumbs/10.png');
window.close()">
As a note, the ?504 is not static and changes each time the image library is open so I cant use it as an id value.
I've tried the following lines of code in turn, all without success (gleaned from google and stack overflow).
find("img[#alt='Find Us']").click
$browser.cell(:text => "Find Us").click
$browser.image(:src => /10/).click
$browser.image(:src => "/10.png").click
$browser.link(:text => "Find Us").click
any help would be appreciated
Try identify by :alt :
$browser.image(:alt => "Find Us").click
But, it's strange, cause, $browser.image(:src => /10/).click - must work also.
I agree with Alex and Justin that using src should work, but
Have you tried using an XPath?
Something like browser.img(:xpath => "/html/.../img").click
You can get the XPath to the image pretty easily with Chrome by right-clicking the image-->Inspect Element-->then right-click on the relevant line of HTML in the developer tools that have opened. If the image is always in the same place on the page (regardless of any change in the src), this method should work.
I am trying to retrieve, modify, and reinsert some text in a pop up dialog using watir web-driver. All was going swimmingly until I tried to find a way to click the "Save Book Info" button pictured here: http://i.stack.imgur.com/pGdln.png
However I am unable to find the button. To access the pop up box I gather all the links with the correct name into an array:
#browser.imgs.each do |img| #The links are imgs
if img.title.include?('Edit/Delete Book')
#books << img
end
end
From there I can access the links with #books[index].click. I am able to access and edit the text_fields with:
url = #browser.text_field(:name=>'url').value
... do stuff with url ..
#browser.text_field(:name=>'url').set url
But when I try and find the "Close" button I only get the buttons that are on the main page. After many headaches I managed to find the title of the window I want to work with using #browser.div(:class=>'dijitDialogTitleBar').title, which returns "Edit Book". Success! No. I still can't figure out how to access the buttons on that popup!
If anyone could help me with this I would be most grateful. This is my first time using Watir so it's probably a simple answer...
If more information is needed I'd be happy to supply it. Thanks in advance.
EDIT
Here is the html for the button:
<span id="dijit_form_Button_2_label"
class="dijitReset dijitInline dijitButtonText"
dojoattachpoint="containerNode">Save Book Info</span>
It looks like you have a span tag that is styled to be looked like a button. You need to access it is a span instead of a button.
Try:
#browser.span(:text => 'Save Book Info').click
Page link I am working on is http://www.whatcar.com/car-news/subaru-xv-review/260397
I am trying to automate 'clicking the google link' but am having no luck and keep receiving an error.
Link HTML:
<a tabindex="0" role="button" title="" class="s5 JF Uu" id="button" href="javascript:void(0);" aria-pressed="false" aria-label="Click here to publicly +1 this."></a>
My code:
#browser.link(:class, "s5 JF Uu").click
Error message:
unable to locate element, using {:class=>"s5 JF Uu", :tag_name=>"a"} (Watir::Exception::UnknownObjectException)
./step_definitions/11.rb:12:in `/^On the page I click 'Twitter' , Facebook and Google button$/'
11.feature:8:in `When On the page I click 'Twitter' , Facebook and Google+ button'
The link is inside a frame. To make it even more fun, frame id is different every time the page is refreshed.
browser.frames.collect {|frame| frame.id}
=> ["I1_1323429988509", "f3593c4f374d896", "f4a5e09c20624c", "stSegmentFrame", "stLframe"]
browser.refresh
=> []
browser.frames.collect {|frame| frame.id}
=> ["I1_1323430025052", "fccfdf9410ef34", "f11036dad706668", "stSegmentFrame", "stLframe"]
I1_1323429988509 and I1_1323430025052 is the frame. Since I1_ part is always the same, and no other frame has that, you can access the frame like this:
browser.frame(:id => /I1_/)
Since there is only one link inside the frame:
browser.frame(:id => /I1_/).as.size
=> 1
You can click the link like this:
browser.frame(:id => /I1_/).a.click
Or if you prefer to be more explicit
browser.frame(:id => /I1_/).a(:id => "button").click
That will open a new browser window, and a new challenge is here! :)
The technical answer:
The class of the button on the page that you linked is different for me than the class that you list. It looks like it behaves differently based on the cookies on your local machine (which would be absent during a Watir-driven Firefox or IE session).
You would need to find a different element that is not dynamic to hook into.
The ethical answer:
It is questionable that you are attempting to automate the promotion of online articles through social media. Watir/Watir-Webdriver is not a spam bot, and the services you are using specifically prohibit the use of automation/bots.
That 'button' link is inside an iframe. Read on the watir Wiki how to deal with stuff in frames. If that's not enough to get it working please edit the answer with revised code and error etc and we can work it forward from that point.
I am having trouble getting selenium RC to click on a button. There is a button on a page that has the character "pi" on it and I am trying to click on it. The html code looks something like this
<div id="abc">
<a class="my keys one" keystring="Pi" keyvalue="π"
π
</a>
</div>
This is what I have done so far -
selenium.click("//div[#id='abc']/a[1]");
This returns an OK but on the page, when I see visually, the button is not clicked (on click, the page has to do something).
I have tried other stuff like getting the Attribute and making it click on it, but doesnt work-
selenium.click(selenium.getAttribute("//div[#id='abc']/a[1]#keystring"));
I have even tried converting the above selenium.getAttribute to a unicode value and then clicking on it. That does not work too.
Also, I added a line to check if at least selenium thinks the character pi is present on the page. I used the unicode of pi-
selenium.isElementPresent("\u03c0");
On eclipse, when I run it, this shows up- isElementPresent[?, ] on session...
and returns a false.
I am stumped. Can anyone please point to me what is it that I am doing wrong?
i thin this may help you.
selenium.click("//a[#class='my keys one']");
or
selenium.click("xpath=//a[#class='my keys one'"]");
if it is not workin use css path.
I a similar issue. My button has a "black down-pointing triangle" on it and none of the other attributes are unique (the "class", "id", and "role" are reused over and over on the same page). The only unique thing I have is a "value" that is a symbol.
value="▼ "
I, too, would like to know if there is a way to click on this button.