Use of 'ClickAt ' selenium command - selenium

I'm confused about the difference between the Click and ClickAt commands in selenium. Where can I use the ClickAt command?

Here are what Selenium IDE says about those two commands :
click(locator) Arguments:
locator : an element locator
Clicks on a link, button, checkbox or
radio button. If the click action
causes a new page to load (like a link
usually does), call waitForPageToLoad.
And :
clickAt(locator, coordString) Arguments:
locator : an element locator
coordString : specifies the x,y position (i.e. - 10,20) of the mouse
event relative to the element returned
by the locator.
Clicks on a link, button, checkbox or
radio button. If the click action
causes a new page to load (like a link
usually does), call waitForPageToLoad.
click is used when you just want to "click" on an element, like a button, a link, ...
And clickAt is used when you want to "click" on a position designated by mouse coordinates.
I suppose the second one can be useful for some "rich" applications -- I've actually never used it... On the other hand, I use click like all the time.
If you have a page with form elements, links, buttons, and stuff like that, you'll probably generally use click : it's way easier to find an element using it's id or classname than having to find it's position in pixels on the page ^^

I noticed some differences between click() and clickAt() when testing a ExtJS app.
For example, if I try to click a tab in a Ext.TabPanel, click() command does not work, although I provide it with an correct xpath, and clickAt() works fine.
Code looks like this:
click("//li[#id='tab-panel-id__second-tab-id']/a[2]/em/span/span")
doesn't work, but
clickAt("//li[#id='tab-panel-id__second-tab-id']/a[2]/em/span/span","0,0")
works.
Notice that coordinates are (0,0)
I can't figure out why this happens...

I'm testing a GWT application and it seems like I have to use clickAt if I want to click on a node in a tree widget.

Be careful when testing clickAt. Sometimes double clicking the command will cause it to show up red. You will change the line to try other alternatives but nothing will work. But then run your script and the clickAt line will be fine with whatever you type in.

There is a dojo widget at our application which only works with clickAt("//span[#id='mastheadIconBar']/span[1]/span/span","0,0").
Don't know why, but only click("//span[#id='mastheadIconBar']/span[1]/span/span") does not work.

Related

Click not working on combo-box down arrow button karate UI testing

I tried clicking on down arrow button for a Combo Box (Select is not available. Its a React JS application and once I click on arrow button only list shows selection items) using below karate command but click not happened in application and no error displayed. [The same xpath worked in selenium click command,and showing unique item on Inspect search]
And waitFor("//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div")
And click("//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div")
Note: Then I tried below command
And assert('//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div').exists
and got error
javascript evaluation failed: assert('//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div').exists, :1:19 Expected , but found root
assert('//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div').exists
It would really help us if you follow this process, it is simple and should not take much time for you to give us a small snippet of static HTML (or you can mix react if really needed).
https://github.com/intuit/karate/tree/master/examples/ui-test
EDIT: you also seem to have mis-matched single and double-quotes in your code.
Also note that you should be able to fire a JS event or click by using the script() API. See this example: https://github.com/intuit/karate/tree/master/karate-core#script
So this is an alternate approach to be able to overcome any tricky situation that comes up.

Is the Selenium click() recognized as human or automation?

My scenario which produces the question goes something like below:
I enter a webpage via normal means, next I press on a button, to start a HTML5 application on this webpage, this application is inside an iFrame. On application start I'm being prompted to either turn the sound on or off. At this point there are two possible outcomes:
1. When I answer this prompt manually, new buttons appear in the application window, as expected.
2. When I answer this prompt through automation via Appium, new buttons do not appear.
Now to the question:
To answer the prompt I use the click() method from Selenium. Is it possible that this click() is not considered to be executed by a human and therefore doesn't trigger necessary things? And since I don't have access to the source of the application can I force the Selenium click() to look exactly like a human click?
Here is the code I use to execute the mentioned click:
//Application loading up, hence the sleep
Thread.sleep(5000);
AppiumTestBase.getDriver().switchTo().frame("e_iframe");
Thread.sleep(5000);
WebElement soundOff = AppiumTestBase.getDriver().findElement(By.id("soundOff"));
AppiumTestBase.getStandardWaitTime().until(elementToBeClickable(soundOff));
soundOff.click();
The program is able to find and switch in to the iFrame, there are no cross-origin issues either. The AppiumTestBase is just there for initializing the driver, setup capabilities etc. I also tried clicking the element via Actions and JavaScript, but there was no change in behavior.
In C# a workaround I've found to actually take control of the mouse and move it/click with it is to use "Microsoft.VisualStudio.TestTools.UITesting" for the Keyboard/Mouse libraries. From there, you can tell it "Mouse.Click(new Point(X, Y));"and it will move your mouse to that location and click.
Sample Code:
using Microsoft.VisualStudio.TestTools.UITesting;
var soundOff = AppiumTestBase.getDriver().findElement(By.id("soundOff"));
Mouse.Click(new Point(soundOff.Bounds.X, soundOff.Bounds.Y));

selenium IDE displays hidden div then immediately closes it

I have a hidden div element that when I click the link the visibility changes. In my Selenium IDE script I click the link and I see the div open but then it immediately closes. The rest of the scripts run, but in a demo I would like to keep that div open.
My steps are:
click [Link that shows hidden div]
-->It is here that it displays and then immediately hides it.
focus [element inside div]
assertValue [target element]
Is there a setting that I need or a step that needs to be added?
It's hard to suggest. But there are some things that you can try.
First of all maybe your div is going to hide when link is not under
the mouse. Than you can use mouseOver
Maybe if you need just to verify variable you do not need even see
the div. Selenium IDE can take the value from element that is not
visible. It is not a fare play but sometimes you can do it.
Another way is to use javascript to bring your div to the light:
getEval | window.document.getElementById('your_divs_id').set_attribute('style','');
The most brutal and not trustable way to try to do it to add command
getEval | window.stop()
right after the click.

Watir Radio Button not found

I want to set this radio button in Watir but it is not finding it:
HTML:
<input type="RADIO" style="-moz-user-focus: normal;" tabindex="2421" handlenativeevents="false" value="3G" $9a="$9b" $89="isc_RadioItem_3" id="isc_1HV" name="network">
Ruby:
if BROWSER.radio(:value => '3G').exists?
BROWSER.radio(:value => '3G').set
end
Could it be because our code contains uppercase RADIO? (Generated by SmartGWT)
Any workarounds for this?
Check the DOM to see if it is within a frame, or some container that is causing problems. If you cannot access the radio button by value you can reference it by something else, like index. Find the radio button's container, and reference it by the Nth index. So if your button is the second button in table 12 of table 1 you can hone it down like this:
BROWSER.table(:index, 1).table(:index, 12).radio(:index, 2)
Or if it's the 2nd radio button on the page (always) then...
BROWSER.radio(:index, 2)
You can also reference a radio button by other things:
BROWSER.radio(:value, '3G')
BROWSER.radio(:name, 'network')
BROWSER.radio(:id, 'isc_1HV')
For further help I'd need to know if you can reference other element in the same container on that page. For info on how you can reference an element, see here: HTML elements supported by Watir
And if you get totally stuck, you'll need xpath. But this should be a last resort, frankly.
Another alternative. If it's not responding to radio because it's not a radio button (as Watir would understand it) then you need to find another way to click the object. You can try clicking the container for it to see if that works, but if not then you'll need to use a hardware click. You can find a hardware click solution as a duck punch (it's under one of my answers: here). You can customise this code to accept x and y modifiers, if you like, then you can use .left_click to hardware click any element, including containers. So left_click the RADIO container with x and y modifiers pointing to the radio button. This is slighly more dynamic than just hardware clicking on an absolute x/y position, but it will take your mouse cursor off you and use it to click the screen. I hope this helps!
Could be in a frame, possibly. The error message should point in the right direction.

How can I find text location with Selenium?

I'm trying to find the location of some text on a web page using Selenium.
I can use the isTextPresent function to tell me if the text occurs, but then I want to know where it actually is.
The wider problem is that I want to click on this text.
The problem is that I don't seem to be able to click on this text, which I think is in some control embedded on the page. So, it doesn't seem to be detected as a link or button or option etc. However, I need to click on it to make a selection.
Any thoughts?
Your solution xpath=//*[text()='hello'] will click the first clickable element with the text "hello" in the source code. If you want to be more specific, you can add more cases to the xpath like this
xpath=//*[#id='exampleId']//*[text()='hello']
Now this will click element with text 'hello' that's found after some element with id 'exampleId'.
Xpath is great usage and you should answers above. However, I realised, that sometimes Selenium does not allow you to click something, because it thinks the text is hidden by CSS
So far I do not have any workaround for it and instead of clicking a button I am closing completly whole browser window.
But in my case its div hidden by CSS showing actual version number of such application. So I only take a screenshot of it:
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
File destination = new File("path/to/outputfiles/versionNumber.png");
FileUtils.copyFile(scrFile, destination);
Got it !
I don't know the answer to how to find the location,
but, the more important bit is to click on that text.
I can just use an XPath locator in the click method, like :-
Click(xpath=//*[text()="hello"])
This will click on the element that has a text value of "hello".
In my case, this is unique, so that's specific enough.
${x_axis}= Get Horizontal Position xpath=//*[text()="Log files"]
Get Horizontal Position returns the position of 'Log files' wrt the left end(X-axis length).
the position is an integer value... so can be compared easily as well.