How to send keys to Ionic 4 input with Appium? - appium

I am using Ionic 4 (beta) and am unsure what the best (/easiest) way is to send keys to an input field using Appium.
Ionic HTML code:
<form>
<ion-item>
<ion-label position="floating">E-mail</ion-label>
<ion-input [formControl]="email" id="sign-in-email-input" type="email" autofocus="true"></ion-input>
</ion-item>
</form>
In my appium test I want to send keys to this input. I notice in Chrome dev tools that below the ion-input a native input is created by Ionic, which is in a shadow dom. So -after some googling- I go after it like this:
email = driver.find_element_by_id('sign-in-email-input')
jsCommand = "return arguments[0].shadowRoot.querySelector('input');"
emailNative = driver.execute_script(jsCommand, email)
emailNative.send_keys('test#test.com')
But the send_keys command throws "StaleElementReferenceException: Message: Element is no longer attached to the DOM".
I'm going around this by doing:
email = driver.find_element_by_id('sign-in-email-input')
jsCommand = "arguments[0].shadowRoot.querySelector('input').value = 'test#test.com';"
driver.execute_script(jsCommand, email)
That seems to work at first (I see the value appear in the IOS simulator). But when focus moves to another field, the value disappears.
What is the correct way to send keys with Appium to an input in Ionic 4?

Related

In google sheets add some kind of dialog box that will display on an ipad

I am trying to add a yes/no message box to a google sheet that will display on an iPad. I have tried all the things below but none of them display the message. My goal is if the user changes a field the macro will change other fields if the user says it is ok. I can get this to work on a windows machine with no issues but when I try it on an ipad the message never appears. At this point I am just trying to get a message box to appear. This is what I have tried
1.
function onEdit(e) {
Browser.msgBox("test");
}
Result: The macros times out
2.
function onEdit(e) {
var html = HtmlService.createHtmlOutputFromFile('Page')
.setWidth(400)
.setHeight(300);
SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
.showModalDialog(html, 'My custom dialog');
}
Page.html:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
Hello, world! <input type="button" value="Close" onclick="google.script.host.close()" />
</body>
</html>
I enabled the trigger for onEdit to get it to work and it works on the windows machine without issues but when run on the iPad I get:
Exception: You do not have permission to call Ui.showModalDialog. Required permissions: https://www.googleapis.com/auth/script.container.ui
So next I tried:
3.
function myFunction(){
Logger.log("myFun")
var html = HtmlService.createTemplateFromFile( 'Page' )
.evaluate()
.setWidth( 800 )
.setHeight( 400 );
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.showModalDialog( html, 'My page title' );
}
function onEdit(){
ScriptApp.newTrigger('myFunction')
.forSpreadsheet(SpreadsheetApp.getActive())
.onEdit()
.create();
}
Using the same page.html, this time in executions it looks like it runs but no box appears on the ipad(it does work on windows). I also tried spreadsheetApp.getUi().alert and prompt, these had the same results.
And Yes I have to use the iPad, I can not use another type of tablet.
Issue:
"Exception: You do not have permission to call Ui.showModalDialog. Required permissions: googleapis.com/auth/script.container.ui"
Fix:
What you can do is installing the trigger instead of using a simple trigger. The image below shows the difference between an installed (above) and a simple (below) trigger using the same code.
Output:
Note:
Don't use reserved function names on installed triggers to avoid it being executed twice like what's shown above. Change onEdit to something like promptUI or something else.
If the above fix isn't enough to show the dialog box, then we need to confirm if the issue might just be on the safari browser (if you are using one) since it worked on your other devices which I assumed are not using safari. You can try using an alternative browser in your device such as Google Chrome and see if the same issue persists. I recommended doing this since i'm seeing a number of issues between showModalDialog and safari
EDIT:
I have seen these related posts pointing out that there are some limitations on mobile apps. See the references below.
Also, some answers suggests that you need to access the spreadsheet via browser (google chrome desktop mode) and then trigger the script there.
References:
Add a script trigger to Google Sheet that will work in Android mobile app
google speadsheet api onOpen does not work on mobile ios
Executing Google Apps Script Functions from Mobile App
How to get scripts to work with phones and tablets

MVC Datalist is not working on prod server but works on Dev

I have an application that uses a datalist that works in the Dev environment but returns a blank field with no lookup in the Production environment. I want to use datalist extensively as it easily provides an auto complete facility but cannot until it works in Production.
Dev is MVC VS 2010 on IE 11.0 under Win7 and it scores 302 in the HTML5Test.
Production is IE 11.0 on Server 2012 R2 Standard reported as Win8.1 and scores 312 in the HTML5Test.
After much comparing, checking, trying, inspecting and reviewing I have found the source of the issue that stops datalist working.
MVC View Code in Index.cshtml
This is the eventual experimental code trying to isolate the issue:
#model IEnumerable<CRM_MVC.Models.BranchDiary>
#{
Layout = null;
}
<body>
<div>
<lable>Enter TV Series Name </label>
<input type="text" id="tv" name="series" list="tvseries" autofocus>
<datalist id="tvseries">
<option value="Heroes">
<option value="Lost">
<option value="Fringe">
<option value="CriminalMinds">
<option value="CSIMiami">
</datalist>
<p><strong>Note:</strong> The datalist tag is not supported in Internet Explorer 9 and earlier versions, or in Safari.</p>
</div>
</body>
Internet Explorer session showing Index.cshtml
The field should provide an autocomplete dropdown but doesn’t.
The Inspect screen shows that <datalist id=tv> is wrongly terminated by /datalist on the same line and after the option list /datalist wrongly has //datalist appearing after it.
When right click Edit HTML is selected for the Div, the original HTML correctly has the first datalist tag with no /datalist and the option list is correctly terminated at the end by the /datalist tag.
What can be done to stop the extras being added to so that it might work the same on Production as on Dev?
What resolved this was unchecking Display intranet sites in Compatibility View in IE Tools-> Compatibility View Settings.
Thanks to Mr Lister for this suggestion.
I will need to check to see if globally changing this setting affects anything else but it makes autocomplete work now as expected and required. Thanks again to Mr Lister for the assistance.

Geb - Selenium Input focus with datepicker

Since upgrading to Geb 0.12.2 and Selenium 2.48.2, I cant get the following to work:
$("form").validOn(dateString)
I have tried variations like:
$("input",name:"validOn").value(dateString)
and
$("form").validOn << Keys.chord(Keys.CONTROL, "a")
$("form").validOn << Keys.chord(Keys.DELETE)
if(date){
$("form").validOn << date
}
The element I am trying to set is using a jquery datepicker:
<form class="form-inline">
<label>Valid On:</label>
<input size="10" type="text" id="datepicker-validOn" name="validOn" value="${validOn}">
...
</form>
..
..
<r:script type="text/javascript">
$("#datepicker-validOn").datepicker({
format:"${session.sessionPreferences?.globalDatepickerFormat}"
});
...
The datepicker is opened which means that selecting the field works, but the string value is not placed inside the input field. I suspect that this has to do with the focus moving to the datepicker, but have not found a way to fix it. I tried having two .value(dateString) hoping that the second will return focus to the field but this has not worked. Also, the original html is not altered by the datepicker.
I am using firefox 33.1.1
This only happens on headless environment, using Hudson with Xvfb to run the functional tests. Running locally on desktop with same version of firefox works as expected, using this format : $("input",name:"validOn").value(dateString)
Any suggestions?
Changing the resolution for Xvfb from 1024x1024x24 to 1600x1200x24 has fixed the issue.. Not sure how this could affect the element focusing, but apparently it does.

Get value of an input element on a firefox addon

How i can fetch the value of this input element in my main.js:
<input type="hidden" value="12124054" id="ctl00_cphContent_hdnID" name="ctl00$cphContent$hdnID">
I tried var id = document.getElementById("ctl00_cphContent_hdnPlayerID").value; and contentWindow.document.getElementById("ctl00_cphContent_hdnPlayerID").focus(); but i am getting errors that document and contentWindows are unidentified :(
You need to get the value from the page using a content script and then send the value to main.js - this is because web content is inherently untrusted by the addon-sdk. Please see these docs for more on how to use content scripts:
https://addons.mozilla.org/en-US/developers/docs/sdk/1.0/dev-guide/addon-development/web-content.html#content_script_events
Here is an example add-on on Builder that shows how to pass values frmo the content script back to main.js. In this case I'm using the xui library to more easily bind events in the pgae.

iOS Mail.app line-break in text body

I have a simple div with onclick attribute. The attribute contains a mailto achor tag so if the visitor click on the div his/her mail client pops up with a new mail window.
My problem is that I have a sample tag in the mail body with line breaks. In OS X Mail.app, Windows' Outlook, Gmail and even in my Windows Phone 7.5 default mail client it works perfectly but on my iPhone or iPad there are no line-breaks.
For line-breaks I use the following code: \u2029.
I copy the whole code so you can understand my problem:
<?php
$linebreak = '\u2029';
$signup_email = 'hello#company.com';
$signup_subject = 'Signup';
$signup_body = 'Dear Company,'. $linebreak . $linebreak .'I would like to signup as the following'. $linebreak .'My name: '. $linebreak .'My e-mail: '. $linebreak . $linebreak . $linebreak .'Best regards, '. $linebreak;
?>
<div id="signup" class="left" onclick="location.href='mailto:<?=$signup_email;?>?subject=<?=$signup_subject;?>&body=<?=$signup_body;?>';">Signup</div>
The sample text is just a sample text, I don't want to make a signup form like this (it would be so lame (: )
OK, I just figured it out.
In this post the author says you should use %0D%0A squence to break lines. And it works! I tried in Gmail, OS X default Mail.app, MS Outlook and Thunderbird on Windows XP/7, Windows Phone 7.5, iOS 5.1 and iOS 4.2.1.

Resources