can not find element using watir webdriver - ruby

I am trying to click on the button.
<input data-ember-action="797" value="Search Now" class="cta-1st clrboth primary search-button firepath-matching-node" type="button">
but it keep showing an error of not finding the element to click.
it finds all the elements until the end but when it comes to "click" it throws an error. My code is like this:
#browser.div(:id=>'ember730').section(:class=>'tab-pane fade active in').form(:class=>'flight-search ').input(:class=>'cta-1st clrboth primary search-button').click
Am I missing something?
I am using Watir

Thank you for all the help here. the problem was, I had a wrong reading in one of the elements.
I was missing this part.
#browser.div(:id=>'ember730').section(:class=>'tab-pane fade active in').form(:class=>'flight-search ').text_field(:class=>'cta-1st clrboth primary search-button firepath-matching-node').click

As there is value="Search Now" section of type="button" here, following simple code snippet should do. I have made this working using Watir in my project..
#browser.button(value: "Search Now").click

Related

Not able to check checkbox elements in Laravel Dusk

I'm trying to do test cases for my application on Laravel 6.0 with Dusk. I'm facing some difficulties in checkbox selection, it is not finding the 'check' element.
As per the documentation I have used the check method and defined the selector with id
My ID is : company-search-type-Investor and my code is:
$browser->scrollToElement('#company-search-type-Investor')
->assertNotChecked('#company-search-type-Investor')
->check('#company-search-type-Investor')
->pause(1000)
Its strange that my test with ->assertNotChecked('#company-search-type-Investor') gets passed but ->check('#company-search-type-Investor') gives an error:
Facebook\WebDriver\Exception\UnrecognizedExceptionException: element click intercepted: Element <input data-v-c1e51704="" id="company-search-type-Investor" type="checkbox"> is not clickable at point (192, 497). Other element would receive the click: <label data-v-c1e51704="" class="kt-checkbox" style="margin-bottom: 6px; font-size: 1.1rem;">...</label>
Any suggestions are welcomed. Thanks.
This could be happening because CSS is being applied that moves the checkbox behind the label. There are two ways to check the checkbox.
You can call click on the label:
$browser->click("label[data-v-c1e51704='']");
You can call sendKeys on the checkbox:
$browser->element("#company-search-type-Investor")->sendKeys(WebDriverKeys::SPACE)

protractor using xpath //*[contains('text')] error element not visible

Hi I have this element from a dropdown menu I try to select:
<div class="tt-suggestion tt-selectable">
<strong class="tt-highlight">Auto Customer</strong>
</div>
If I use element(by.xpath("//strong[contains(text(),'Auto Customer')]")).click(); I can select it no problem. But if I use element(by.xpath("//*[contains(text(),'Auto Customer')]")).click(); I get "Failed: element not visible"
Can someone explain this to me please?
Thank you
Because the * in //*[contains(text(),'Auto Customer')] means any tag, not only the strong Tag. But //strong[contains(text(),'Auto Customer')] must be strong Tag.
//*[contains(text(),'Auto Customer')] should find more then one elements on page, and the first one is not visible. You can try this xpath in Chrome DevTool's Element Tab to see how many elements it can find and the first one is visible or not.

capybara ruby code to check an element is present or not

using capybara how can i check an element is present or not.
i used following code but it is not working
page.should_not have_selector('#confirmation_code')
<div style="width:250px;display:block;float:right;text-align:right;">
<span id="email_text">Order Number:<br></span>
<input id="confirmation_code" type="text">
</div>
i want to check above text box element is present or not?
So going from the last comment from Sush,
The first line in the code in the question is not correct at all. That will verify that the element is not shown.
You could use the following instead:
page.should have_css('#confirmation-code')
or if you wanted the text within do this:
page.find('#confirmation-code[type="text"]')
I will be honest though I am going by what I think the question is, it is not very clear what you are looking to achieve.

Selenium click() or isSelected() are not executed on RadioButton's input element

I have radio buttons that are located inside a table, such as:
<tr id="radiofield-1080-inputRow">
<td class="x-form-item-body" id="radiofield-1080-bodyEl" colspan="3">
<input type="button" id="radiofield-1080-inputEl" class="x-form-field" autocomplete="off">
<label id="radiofield-1080-boxLabelEl" class="x-form-cb-label">My Label</label>
</td>
</tr>
I do find the input element, by the following code:
xPath = String.format("//tr/td[contains(#id,'%s')][contains(label,'%s')]/label", xType, text);
webElement = webDriver.findElement(By.xpath(xPath));
but isSelected() or click() doesn't seem to work on it.
Do you have any suggestion?
Haven't used selenium in a while but from a quick google it looks like you should try the isChecked and check/uncheck methods.
Here's the Javadoc but for some reason can't get a decent link, obviously check on the Selenium object. If you're using a different version or if I misunderstood something sorry.
http://selenium.googlecode.com/git/docs/api/java/index.html
In your code snippet problem with locator.
Use any of the below below locators
By.cssSelector("input[id*='radiofield-']");
By.id("radiofield-1080-inputEl")
By.xpath("//tr/td[contains(#id,'radiofield-')]/input")
Try clicking on the "input" instead of the "label".
xpath of input:
"//input[#id='radiofield-1080-inputEl']"
If the input id is not always the same, you can try this, the location of input will be based off the label:
//label[text()='My Label']/preceding-sibling::input
Thanks for all your answers.
My finding concluded with the following:
ExtJS implement radiobutton and checkbox as button, therefore the selenium isSelected() is not functioning.
There is a need to implement isSelected(), as suggested at:
How to check if extjs checkbox is selected in selenium?
The click() does the work, as it is a button.
Thanks again, Michal

A way around Element cannot be scrolled into view - Watir-webdriver with Ruby

So, we have the following code in our page:
<div class="toggle-wrapper">
<input id="HasRegistration_true" class="registration_required toggle" type="radio" value="True" name="HasRegistration" data-val-required="The HasRegistration field is required." data-val="true">
<label for="HasRegistration_true" class="">On</label>
<input id="HasRegistration_false" class="registration_required toggle" type="radio" value="False" name="HasRegistration" checked="checked">
<label class="checked" for="HasRegistration_false">Off</label>
</div>
These are 2 radio buttons. 'On' and 'Off'. 'Off' is the default value.
Using Watir-webdriver and Ruby, we want to select the 'On' radio button. We do so like this:
browser.radio(:id => "HasRegistration_true").set
But in doing so, we get the following error:
`WebElement.clickElement': Element cannot be scrolled into view:[object HTMLInputElement] (Selenium::WebDriver::Error::MoveTargetOutOfBoundsError)
We know Selenium 2 scrolls the page to the element, so trying to scroll down is useless.
We are always using the latest releases of watir-webdriver and ruby.
We can't change the HTML of the page since we're QA engineers.
Here are two solutions that have worked for me:
There is a Ruby gem called watir-scroll that can work.
Then
require 'watir-scroll'
browser.scroll.to browser.radio(:id, "HasRegistration_true")
If you don't want to add a gem, my co-worker suggested something that somewhat surprisingly (to me) had the same effect as the above code:
browser.radio(:id, "HasRegistration_true").focus
browser.radio(:id, "HasRegistration_true").set
In my code, ".focus" scrolled straight to the element that was previously not visible. It may work for you as well.
First of all try locating the element using XPATH:
browser.element(:xpath, "//input[#id='HasRegistration_true']").click
or
alternatively if it is a hidden element you are trying to locate then you are better off using CSS. Download firebug add-on for firefox and copy the CSS path of your element.
It should be something like:
browser.element(:css => "the CSS path you have copied from Firebug").click
One of the 2 should do it for you!!
Best of luck!
You could manipulate the html on the fly by executing some javascript to make the radio element settable. To execute javascript on a page, do something like:
#browser.execute_script("your javascript here")
I used something like the following javascript to strip the class out of a label tag which moved it out of the way of the input tag I was attempting to act on for a Chrome specific problem I had.
execute_script("$(\"label.classname\").removeClass(\"classname inline\")")
If the element is contained within a form and a div (Wrap) class I found that I had to do the following to click the 'No' radio button on the "https://quote.comparethemarket.com/Motor/Motor/AboutYourVehicle.aspx?" page:
div_list = #browser.form(:action => "AboutYourVehicle.aspx?ton_t=CTMMO&prdcls=PC&rqstyp=newmotorquote&AFFCLIE=CM01").div(:class => "inputWrap").divs(:class => "custom-radio")
And then:
div_list[1].click
Hope this solves your issue too :-)
I'm not using watir but I have the same error as you "...could not be scrolled into view ...". I tried to use watir just to solve it and didn't work for me. Then, I use an ActionBuilder (move_to with click) and the error disappeared.
My line to avoid the error is:
#driver.action.move_to(*webelement*).click.perform
I hope it will be useful for you

Resources