3
votes

First of all... I red everything I could and tried everything I found!!

With the following gems installed in WinXp:

Watir-webdriver 0.6.10 | selenium-webdriver 2.42.0 | Firefox 30

I have a type="button", inside an input tag element, which I'm sure it exists in the browser (returns true to exists?), but that it's not visible to watir (returns false to visible? or present?), despite being visible to the user.

I've tried the .hover, .fire_event "onmouseover", .click and fire_event("onclick") approaches and none solved the problem.

With the first I get a native event problem whether I disable native events in firefox, as suggested in watir webdriver website, or not.

b.div(:class, "buttons btnGuardarCancelar").button(:id, "guardar").hover
b.div(:class, "buttons btnGuardarCancelar").button(:id, "guardar").when_present.click

With the second I get a true answer, but nothing happens, even with a wait_until_present or when_present after that command.

b.div(:class, "buttons btnGuardarCancelar").button(:id, "guardar").fire_event("onmouseover")
b.div(:class, "buttons btnGuardarCancelar").button(:id, "guardar").when_present.click

With the third I get a timeout, saying the element is not visible.

b.div(:class, "buttons btnGuardarCancelar").button(:id, "guardar").when_present.click

And with the last one it fires some other onclick event, but not the one associated with the button I indicate.

b.div(:class, "buttons btnGuardarCancelar").button(:id, "guardar").fire_event("onclick")

Also tried xpath with the following:

b.element(:xpath, "//input[@id='guardar']").when_present.click

and

b.button(:xpath, "//input[@id='guardar']").when_present.click

the code is what follows:

<div class="buttons btnGuardarCancelar" name="">
 <input id="cancelar" class="formButton margingleft" type="button" value="Cancelar"  onclick="openUserServiceConfigMenu(1);" tabindex="12"></input>
 <input id="guardar" class="formButton margingleft" type="button" value="Guardar" name="guardar" onclick="sendForm();" tabindex="12"></input>
</div>

The behaviour is the same for both buttons. I don't know what to do more, to get this working. Important to say that I have no control over the website.

add-ons: 1) it works when interacted directly by a human user. 2) it also doesn't work via irb. 3) i don't need the click any other buttons to access this button.

Edited:

Just tried:

b.element(:css, "div.buttons.btnGuardarCancelar > input[name=guardar]").click

Received the following error:

[remote server] file:///D:/DOCUME~1/p056988/LOCALS~1/Temp/webdriver-profile20140 708-5676-32980a/extensions/[email protected]/components/command_processor. js:8791:5:in `fxdriver.preconditions.visible': Element is not currently visible and so may not be interacted with (Selenium::WebDriver::Error::ElementNotVisible Error)...

4
Selenium and I think it's the same for Watir 'simulate' real user actions. As a user you cannot click an invisible element, so there is no way to click it with Selenium (and I think it's the same) with Watir - singe3
The problem is that I can click the element. The element is there, no doubt ! If I go there myself and click it, it works fine. And I have to click no other buttons or frames or anything to have it available. - filipedilopes
Your HTML code is wrong, <input /> is a single tag. Try changing that, maybe it confuses Watir - singe3
I think that's not the case, since it works when I address other input tag elements with the same structure. - filipedilopes
Is there a reason you need to nest the button definition inside the "buttons btnGuardarCancelar" div? I have had a nearly identical problem (quite recently, in fact) interacting with button elements. I "solved" the problem by changing the parent element I was using with it (getting rid of it entirely, actually), as well as the identifying tag I was using for the button element itself. - Abe Heward

4 Answers

2
votes

Well, found my answer... tried to answer yesterday, but since my rep is still low I couldn't until 8 hours after I posted.

After digging deep in the website code, using the Firefox built-in inspector, I found the issue ...

It seems that there are some other buttons in the same page, with the same identifiers - html just like the one I was trying to address -, but they are hidden and so watir-webdriver tries to click the first it gets in the html page code and it gets a not visible error.

I managed to solve the problem by editing the button parents to be more specific, starting with the first "present?==true" element in the path.

b.td(:class, "tab_user_service_options").div.div.div.div(:class, "buttons btnGuardarCancelar").button(:id, "guardar").click

Thanks for all your kind answers.

Cheers.

0
votes

Sometimes the .click doesn't work. There are many different factors that could cause this and that really depends on the implementation of your application. Utilize the OpenQA.Selenium.Interactions.Actions class to simulate the user movements instead of executing a click event on an element.

    OpenQA.Selenium.Interactions.Actions actions = new OpenQA.Selenium.Interactions.Actions(driver);
    actions.MoveToElement([IWebElementGoesHere]).Perform();
    actions.click().Perform();

This will move the mouse to the desired location and then click it. Based on your previous comments you are able to find the web element so it should function to move the mouse and click there. There is also an actions.click([IWebElementGoesHere]).Perform(); which I have found also usually works, but if it doesn't then you can use the move and then click.

Depending on your application you might have to move your mouse and wait before clicking if there is some behind the scenes actions that take place...but that totally depends on the implementation of your application.

0
votes

The element you are trying to 'click' is most likely being 'covered' by another element (possibly a 'span' element). The element will return 'exists?' but is not 'clickable', "because another element would receive the click"

On the site I'm currently testing the UI guy will use a 'span' to stylize the elements on the page. So where it looks like i'm clicking on a 'button' element, in actuality I'm clicking on the span that is on top of the button element.

I would suggest using Selenium IDE and recording the flow, it should give you some clues as to the element you can use in your script.

0
votes

As per the documentation of Watir, it first check whether element exists(Returns whether this element actually exists), and which doesn't check element is visible or not. So before performing any action,it is necessary that element should be visible.

def click
  assert_exists
  assert_enabled
  @element.click
  run_checkers
end

I generally check for presence for element and then check whether element is preset or not. If not use, wait_until_present and then perform any desired action.

browser.element(:css => locator).wait_until_present
browser.element(:css => locator}").click

Try out this and revert if this works for you!