I am facing an issue, In this case terms & conditions and privacy policy. two links are part of one class only and I am not able to click on privacy policy, but terms & conditions click works all the time by using that id.
There is no easy way to do this since Appium recognises it a a single element.
Luckily, you can do the following steps:
Find the TextView element
Determine the position of the elements top-left corner
Determine the TextView width and height
Calculate approximate coordinates for Privacy policy link based on width/height and start position (top-left corner)
Use the Actions
API tap method to click by coordinates
There is an article from Appium team that addresses a similar issue and provides Java code sample.
Related
I'm new to Appium and automation in general.
I'm trying to write a login test. I have six separate LinearLayout elements and in each of them I need to insert the value "1". I can identify the element (e.g. the element with the id "container_zero"), but I cannot send the value to it neither with the sendKeys() nor with the setValue() method.
Also, I tried just to type the required digits using the keyboard below (see the screenshots). But as this is a custom keyboard of the app (not a native Android keyboard), I cannot interact with it. I tried the method driver.pressKey(new KeyEvent()) with AndroidKey.NUMPAD_0 and AndroidKey.DIGIT_0 parameters - didn't work. Keyboard has none elements inside on which I could click (it's just a single element with the android.view.View class).
I also have an idea to press the required digit on the custom keyboard using the coordinates (X,Y), but I don't think that this is a good way out (maybe when I launch the test on different devices, the coordinates will be different - correct me if I'm wrong).
Please advice what can I do? I thought about using Espresso at this point, but we have the same app on iOS, so for now I think I would try to stick to the Appium for a little while longer due to its cross-platform feature.
but I cannot send the value to it neither with the sendKeys() nor with the setValue() method. - that is correct, you can see attributes of the element and it is not checkable, clickable, focusable etc. So that means that you are not able to sendKeys() or even click() on it.
Also, I tried just to type the required digits using the keyboard below (see the screenshots)... - that is the correct behaviour (related to your particular example) too, because there are no different elements of the buttons, only one FrameLayout for the whole keyboard.
I see two scenarios:
You can ask developer to enable button elements so you will be able to click() on it
You can calculate coordinates of these buttons in accordance with screen dimension, for example: 1 button = getWindowSize().getWidth() + 50, getWindowSize().getHeight() / 2;.
This scenario is very unstable because of different devices, but it could work if you find correct dependency between dimension and button positions.
Altogether you either need developer intervention or not so easy calculations for coordinates.
I have 2 exact same images (pattern, color, size ,everything is same) on the screen and in this case how do I click on Image 1?
Whenever I am using the s.click() function, Sikuli tries to click on Image 1 some times and sometimes on Image 2.
I have tried Pattern and exists but they are also not working as expected.
Pattern imagePatternPath = new Pattern("Image.png").exact();
screen.click(imagePatternPath);
I expect to click on Image 1, but the actual output is sometime it clicks on Image 1 and sometimes on Image 2.
If there are two absolutely similar patterns on the screen, there is no way for Sikuli to distinguish them without some help. You have few options to resolve this problem.
location on the screen
If the patterns appear in known areas on the screen, you can limit the search to the expected area and thus, avoid picking the wrong pattern.
search by proximity
If you have any other objects that appear only next to one of the patterns you are attempting to locate but not the other, you can use them as pivots.
Have a look into Sikuli code, especially into the Region class here. It exposes various options to modify the search area around found patterns. For example:
public Region grow(int range) {
return grow(range, range);
}
Try looking at the patch notes next time, they are very helpful. But here is what I would try:
result = findAll("Image.png")
This will return a List which you can iterate through to click the item you wat so in this case you would click the first item.
I'm using vaadin 8.1 in my project.
I needed to give an extra large width to a grid column (the latest at the right), and when user clicks in one field of this extra large column, vaadin move horizontal scroll automatically at the end of the grid. I would like stop this vaadin behaviour. I researched and I tried different things but I didn't find anything,
How can I do it?
Thank you,
Best regards
There is no API in Vaadin to turn it off (You can find feature request here: https://github.com/vaadin/framework/issues/7667). There is one trick you could try, namely disable pointer events in Grid cells. It is a bit harsh method, since it will disable also selection and item click.
In your code
grid.setStyleGenerator(item -> { return "disable-events";});
And your theme
.disable-events {
pointer-events: none;
}
It is possible to add the style generator also for one Column only, which could be option to you as well
I have been put in charge of a site for one of our clients that was built by an outside company. One of the additional requests is that she wants to be able to position an image on their news page either on the left, right or centred.
There is an administration system in place where the client can create a news article and add an image however I need to know if there is anyway I can change the image position on the 'news items' page depending on whether the left, right or centred radio button has been checked on the administration panels 'add a news item' page.
I think it is possible with Java but it's not something I have had to do before and am looking for a nudge in the right direction really.
I think it is possible with Java but the tutorials I have found show me how to change the css with Java on the current page but not on a different page.
Any advice would be much appreciated
Write 2 css classes, class1: for left alignment and class2: for right alignment. Suppose if there are 2 radio buttons. On click of each radio you can toggle value of class.
$("#radioId1").click(function () {
$('#para1').removeClass('class1');
$('#para1').addClass('class2');
});
$("#radioId2").click(function () {
$('#para1').removeClass('class2');
$('#para1').addClass('class1');
});
Right now, I'm using Java Swing to create a JEditorPane primarily for its ability to have hyperlinks. I've successfully been able to display links and have them execute behavior upon a click, but I'm running into a few problems with formatting.
How can I set the cursor so that it normally is an arrow, but changes to a text cursor when hovering over text? (In essence, the behavior a cursor has within a web browser). I tried
EditorPane.setCursor(new Cursor(Cursor.TEXT_CURSOR))
but that made it a text cursor everywhere, even when not hovering over text. Right now, hovering over a link shows a pointer hand; I'd like to maintain that functionality as well.
What is the best way to show tooltips or mouseover text when hovering over a link? I tried modifying the title attribute of the link but nothing showed up.
I was trying to implement links to skip down to a subsection of the page, much like http://en.wikipedia.org/wiki/Xkcd#History would take you directly to the History subsection of Wikipedia's xkcd page. How can I do this?
An answer to any of these would be great (and multiple would be awesome xP). Thanks a lot for your help!
As you said one can simply give answers to a single point as well, let me try one by one, here is the answer for your last Point 3
Just provide an id to your tag like this
<h1><a id = "top"></a>First Line</h1>
Now somewhere in the bottom of your page write this :
<p>Return to TOP</p>
Clicking this link, you will reach the above area of the PAGE.
Points 1 & 2 may be addressed using the approach mentioned here. In particular, the view/model conversion methods will let you condition setCursor() and getToolTipText(), respectively.
You can get source from here http://java-sl.com/JEditorPaneStructureTool.html
It shows how to obtain text view bounds. First you get caret position for current mouse poiunter using viewToModel() method. Then go down the Views tree achieving leaf view and calcualte it's bounds. See this http://java-sl.com/tip_view_rectangle.html
If your mouse pointer in the view's rectangle then your mouse over text.
You can check whether the text in caret position is link and show your tooltip.
Use this http://java-sl.com/tip_links_in_editable.html to see how to detect whether mouse is over link.
Point 3.rd is answered by #nIcE cOw