What will be xpath of attached screenshot appium- robot framework - xpath

I Want to find out xpath of login button from attached screenshots.
I have tried
Wait Until Page Contains Element xpath=//android.view.View[#content-desc='Login']
This return successful for finding element
but it does not click with below line of code
Click Element xpath=//android.view.View[#content-desc='Login']

Maybe you need to check if element is available, for example with:
Wait Until Element Is Visible xpath=//android.view.View[#content-desc='Login']
Or
Wait Until Element Is Enabled xpath=//android.view.View[#content-desc='Login']
I have attached screenshot after performing above steps.please check...

Related

watir element click intercepted:

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

RobotFramework: Goes

Below is code where i go to a new window. I do a screenshot to ensure that i am on the right window
${url}= Get Element Attribute xpath=//*[contains(text(),'Download certificate')]#href
Select Window Containing Url ${url}
Page Screenshot certificates
Wait Until Element Is visible xpath=//*[contains(text(),"SUCCESSFULLY COMPLETED THE MODULE")]
Not found according to error message.
Element locator 'xpath=//*[contains(text(),"SUCCESSFULLY COMPLETED THE MODULE")]' did not match any elements after 30 seconds
However i know from firebug that this xpath will match on the page. My uneducated theory is that the focus is still on the former page - would this be correct and regardless, what can i do to ensure that commands go to the correct new page?
You could use Select Window new.
See documentation here

How to get more detail about error when element not presented, Nightwatch.js?

I using Nightwatch.js + Selenium for acceptance testing and it generates html report after finish.
And sometimes when some element not presented on the page - Nightwatch will return an error, so, this code:
.waitForElementPresent('.block', 15000)
will return this error:
Timed out while waiting for element to be present for 15000 milliseconds. - Expected "found" but got: "not found"
I want to see more details about element which not presented
I really do not get the point,what do you want to know more?
The elements is not found so that it return you not found.
Before you go to code, open the browser, press F12 and find ".block" in element tab, make sure the element is present/visible then code ,or you just right-click on the element you want then chose copy selector.
If you want more detail about the element,go to console tab,paste this one and you will see the detail of '.block' element.
document.querySelectorAll('.block')

Can't click an input type="button" that exists but it's not visible

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/fxdriver#googlecode.com/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)...
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.
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.
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.
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!

How do I let Selenium driver click on link which is dynamically created through JavaScript

I am trying to automate actions and unable to select an element due to its dynamic nature.
I am running Selenium web driver on ruby and am trying to select value that is not present in page source.
<a class="linkOtherBrowser" onclick="addChangeStatusField('InitialSelectionPage');submitFormByAction('ChangeStep');return false;" href="#"><div class="processBarElement noSelected">
<div class="whiteBeforeProcessBarTitles"></div>Initial Selection</div>
<div class="endOfElementOfProcessBar"></div></a>
I am trying to select value "Initial Selection" from above.
Could anyone pls help out?
Thanks,
Abhishek
As the HTML is generated by Javascript, You need to inspect the DOM instead of viewsource and write the element locator code accordingly.
Note: In IE, Firefox or Chrome you can press F12 key to see the developer tools and use the inspect element option to check the DOM.
Whatever element is generated dynamically is added in your DOM. WebDriver has capability of clicking on elements are the visible on UI and hence if the generated element is visible to regular user's you can click on the element easily.
To do so, you need to identify the best selector for that newly generated click, could be xpath or css. Once you identify the selector you can consider clicking clicking using following code
WebElement element = driver.findElement(By.xpath("//a[#title='NAME_TITLE']"));
element.click();
OR
WebElement element = driver.findElement(By.css("a[title='NAME_TITLE']"));
element.click();
There are more options within your By.class on picking the element in best way

Resources