Unable to select an option from Spinner using Appium 1.6 - selenium-webdriver

I am using Appium 1.6 to automate Android UI Tests.
In this image, I am unable to select any country (ex: Japan) from the spinner.
This is the code I am using:
driver.findElement(By.id("com.akkipet.android:id/country_spinner__add_information")).click();
driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("+ "new UiSelector().text(\"India\"));")).click()
What am I doing wrong? After clicking on the spinner, though I'm not able to read the country values, I can read other fields like First Name, Last Name etc.
For now, I am using the tap functionality to tap at the specific coordinates to choose the required option. But this will make it device specific. Further, since the options list varies depending on the environment, I will have to give a different set of coordinates for each environment.
Code for Tap:
touchAction.tap (200, 850).perform();
Could anyone suggest a better workaround?

Try this one. It worked for me.
driver.findElement(By.id("com.akkipet.android:id/country_spinner__add_information")).click();
driver.findElement(By.name("India")).click();

By.Name has been deprecated. Try using findElementByAndroidUIAutomator.
Eg:
driver.findElementByAndroidUIAutomator("new UiSelector().text("India")").click();

Related

Set default date for zul datebox

I inherited a legacy website written in old zul and have to add new datebox component for birthday datepicker.
Have added a constraint to accept dates before a given date but that triggers an error alertbox from start as the date presented/selected by default on the datepicker is today.
I wouldn't want to use a workaround but to all due respect it seems like this is something over the top feature I'm looking for in zk's reality:
The main showcase for zul does include a birthday datebox, but pretty lame as it doesn't contain any constrain on age.
There is zk fiddler to show how the before constrain works, but that just proves my point that it doesn't select the first proper date for default date at least, if there is no clean way of setting it.
There is forum post that proposes a workaround to set the default year, so Zk is most probably incapable of doing this without a workaround.
There is an open ZK Jira issue from 2017 that addresses somewhat this issue, with a proposed solution pretty much the same as the workaround mentioned in the above point - so the hope is kinda lost, have to go on the workaround route.
I did try that workaround (after the forum post, as that has default year), but the workaround doesn't work for me. It does execute the
this.setValue(initialDate);
And I see that the value is set into the datebox's _pop/_value and _pop/_end nodes but no difference is visible on the datepicker box, still today is preselected altough it is greyed out - so no effect.
Still, when I try it in a fiddle with version 6.5.8.1, the oldest engine that exists, it does work, but not locally with v5.0.11.
In the buglist for this version there is no mention of datebox. Tried to look into to some bugs that might be interfering but turns out it was just another episode of me wasting time with this.
Tried in the 5.0.11 sandbox and it doesnt work with that version. The structure of how I use it is imitated in the linked fiddler. Hints on a workaround that works on this version?
ZK 5.0.11 is a bit on the older side currently, so it might not accept exactly the same overrides as later versions. If I understand the issue correctly, it boils down to either
1 - setting a value before Datebox is rendered to have a "initial date" opened in calendar.
I'd say that's the easy way out, since you can use either composing or databinding to set the value of the datebox during page rendering. Here's a small sample using databinding and zscripts, but the same logic should apply from composer with setValue(). You mentioned that this doesn't work for you locally with 5.0.11 though. Can you share the code that you are using for this? Sample code here in fiddle I can run it on local 5.0.11, and it set the date before popup is opened.
or
2 - setting an initial date (which doesn't affect the selected value) but would be the target for the opened calendar.
This is not a default ZK 5 behavior for datebox. If you want that effect, you would need to customize it using an override script. Simplest way in can think of in ZK 5 is to use the open event of the datebox popup here's an example of what it would look like (package in a script tag in a single page for the example, would use a global js file for real deployement) example here

Not able to select a dropdown value using selenium webdriver(Java)

I have no idea what is wrong in the simple code i have written to select a value from the dropdown. I have been watching other tutorials and code samples and i dont find any mistake in my code. Could someone please help me? I have tried running my code in Chrome as well as Mozilla(on two different OS) but still the issue exists.I am posting attachment of the html as well as selenium code.
Also, i am sure the problem is not because i have used wait because even if i comment that line or use it after loading the web page, the issue is there.
HTML
Selenium
Why don't you try clicking on the dropdown and then selecting the value.
tp.click();
and then
Select dropdown = new Select(tp);
dropdown.selectByValue("2");
new Select (driver.findElement(By.id("custtitle"))).selectByValue("2");
OR
new Select(driver.findElement(By.id("custtitle"))).selectByVisibleText("Mrs.");

Cq5 building a number increment/decrement box

the above picture is what i need to build in CQ5, I have been digging around in adobe cq api,
all i have found is Class CQ.Ext.form.NumberField
but that number field only provide something like textfield for you to manually entering number(this is not what i need)
can anyone guide me how to create such number increment/decrement box in cq5 dialog? with some code example please, thanks
You can try CQ.form.Spinner with xtype spinner.
This is a trigger field for numeric, date or time values.
The spinner uses CQ.form.Spinner.Strategy which defines its behavior.
The dialog config snippet is shown here.
<numfield xtype="spinner" name="./numfield" editable="false">
<strategy xtype="number" allowDecimals="false" maxValue="50" />
</numfield>
For further info, check this Spinner API and NumberStrategy API
Have a look at the Spinner Widget with the xtype="spinner". There you can define the strategy of the spinner, e.g. the increment value. I never used it myself though, so I can't provide you with a running code example.

Are there any tools for recording web browser events for seleniumn2?

I am looking for something very simple. It can use the Selenium IDE recording tool, but it does not allow me to pick what kind of locators I get.
I want to use:
driver.findElement(By.className(str))
to locate things. All I need is something which watches which UI elements on a web page get clicked and writes out the class attributes of those tags.
If I use the Selenium IDE recording (and export to the right type of thing), I get:
#Test
public void testNav() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.name("3.1.1.5.1.1")).clear();
driver.findElement(By.name("3.1.1.5.1.1")).sendKeys("dan");
driver.findElement(By.name("3.1.1.5.1.5")).click();
driver.findElement(By.linkText("Products")).click();
driver.findElement(By.linkText("Categories")).click();
driver.findElement(By.linkText("Create a Category")).click();
driver.findElement(By.linkText("Cancel")).click();
driver.findElement(By.linkText("Products")).click();
driver.findElement(By.cssSelector("a.DisplayAdminProductsLink")).click();
driver.findElement(By.linkText("Product1")).click();
There are problems with this. First, it is not give me any By.className() calls. Why? Those first 3 calls will not help me. The framework I am using puts arbitrary things into the name. How can I get it to see the class attribute?
There actually are unique words in the class attribute of all of the above tags. I design my apps so that this is so. Yet it will not use them.
Earlier I asked:
Why is it doing a "driver.findElement().click()"? This is fragile and does not
end up working.
What I need is:
elt = driver.waitFor(By.className("c")); elt.click();
This will work reproducibly.....
I am considering to be removed from the question, as the findElement() code does work. You need to set a general time-out on the driver. It is not very obvious that this can be done, but it can.
So, continuing on....
I can go to the "Options" and change the order of the "Locator Builders" in eclipse. I can put "css" at the top. Then I get:
driver.findElement(By.cssSelector("input[name=\"3.1.1.5.1.1\"]")).clear();
driver.findElement(By.cssSelector("input[name=\"3.1.1.5.1.1\"]")).sendKeys("dan");
driver.findElement(By.cssSelector("input[name=\"3.1.1.5.1.5\"]")).click();
The tags are like:
<input class="form-control LoginUsernameField" ... />
But it does not see the class attribute.... Or I can do this manually.
Selenium looks for a unique identifier to identify elements in a webpage. classNames are a very less desired option for this purpose as they are generally not unique. Ids and names on the other hand are generally unique. This might be the reason why Selenium IDE is not selecting classNames and going for other identifiers.
Selenium IDE records user actions. You would have clicked on the element for Selenium IDE to identify it and that is why you are getting driver.findElement().click().
If you want to wait for element to wait you can try implicit wait.
When you want to use driver.findElement(By.className(str)), are you sure that there is one and only one element in the webpage that is associated with a className? If that is the case you can modify the webdriver code manually to use className.

KDevelop: transform selected text?

I was wondering whether there was a function in KDevelop similar to the one that we used to have in Quanta (miss you, Quanta, btw).
I would like to set a keyboard shortcut, and apply a text transformation upon hitting it. Example:
I select my text to be translated, and I get back: <?=_('my text to be translated'?>
As you can see, this saves me a lot of awkward keystrokes...
I only found this feature in PHPStorm (where it is called "Live Templates"). I defined it like this: <?=t('$SELECTION$')?> and I can call it by hitting CTRL+ALT+J, and select it from the dropdown that appears.
You should be able to do that using a snippet with the following text: <?=_('%{selection}'?>
And you can bind a Shortcut to a snippet.
However my tests showed that this doesn't work correctly - there seems to be a bug somewhere.
As alternative you can write a script that does insert the text. See the documentation.

Resources