Appium Submit Url - webdriver

I am using Python and Android Chrome. And my WebDriver is created using WebDriver.Remote(host, caps)
I actually want to use Chrome in incognito mode but it seems not possible according to the question here.
But are there any workaround? For example, can I submit my url to the url bar of Chrome at the top? I have tried driver.find_element_by_id('com.android.chrome:id/url_bar').submit() but it says not implemented.

This is my workaround. Explanations are in the comments.
# Open Menu/More Button
d.find_element_by_id('com.android.chrome:id/menu_button').click()
# Click On Incognito Mode
d.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.ListView/android.widget.LinearLayout[3]').click()
# Find Url Bar on the top
url_bar = d.find_element_by_id('com.android.chrome:id/url_bar')
# Click on it which gives you another view.
url_bar.click()
# Set url and this gives you a list of options
url_bar.set_text('https://a.lianwifi.com/app_h5/jisu/wifiapk/sms.html?c=uvtest&type=1')
# Click the first one. This is the one that leads you to the page with your url.
d.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.ListView/android.view.ViewGroup[1]/android.view.ViewGroup').click()

You're trying to mix 2 incompatible approaches to mobile automation using Appium.
If you want to use Selenium API normally in order to control mobile browser like a desktop browser:
Instantiate your AppiumDriver like:
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['browserName'] = 'chrome'
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
then to open the URL just use driver.get() function like:
driver.get('http://example.com')
If you want to use Appium API and treat Chrome as any other mobile application you need to provide a little bit different set of desired capabilities and specify Chrome package and activity
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['appPackage'] = 'com.android.chrome'
desired_caps['appActivity'] = 'com.google.android.apps.chrome.Main'
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
Check out Appium - > Code Examples -> Python article for more information on automating mobile browsers/applications including code snippets

Related

R Shiny - Run application in background and issue UI controls with code

I am writing a vignette for my Shiny application package. At the beginning of my vignette, I source a file called screenshots.R that produces nice screenshots of my application. I am producing them like so:
webshot::appshot(mypackage::run_datepicker_app(),
file = "man/figures/datepicker.png", vwidth = 500, vheight = 200)
This works great and it gives me a great screenshot of what is - in this case - a couple dateInput fields. However, I'd like to be able to get a screenshot of the dateInput in use (say, with the calendar selection exposed).
Is there a way to issue commands to the application object in a script so I can get screenshots of the application in use, rather than having to do it manually?
Have you tried using ShinyDriver from the shinytest package?
You can use shinytest to have a headless browser run the app, interact with it, and take screenshots programmatically. If you don't have phantomJS installed, you'll need to run shinytest::installDependencies() before using ShinyDriver. All you need to do is point it to a directory containing a shiny app (in my case, the folder is 'myApp').
install.packages("shinytest")
shinytest::installDependencies()
app <- shinytest::ShinyDriver$new("myApp")
app$takeScreenshot("screenshot1.png")
button <- app$findElement("#button")
button$click()
Sys.sleep(1)
app$takeScreenshot("screenshot2.png")
app$stop()
I am starting the app in a headless browser, taking a screenshot, finding the button with the id 'button', clicking it, and taking another screenshot, then closing the app. Navigate to specific elements using "#id", where id is just the id you gave the shiny input. You can specify a file path to a png file in the takeScreenshot calls, so that you can then use them in your code elsewhere. Note that you may need to use Sys.sleep to stop the screenshots from being taken before the UI updates.

Silent printing (direct) using KIOSK mode in Google Chrome

I am developing an application which generates pdf using ITextSharp and need to print silently or directly. My work flow is Like this, I have some forms listed in tree structure and on selecting the forms and click on the print button will automatically generate the pdf using Itextsharp and save to a location. this is because for multiple record we download it as zip file . And goes to print without opening any other windows. I am using google chrome as browser and uses the KIOSK mode.
But unfortunately when i execute the code the print preview will open up in my browser and i need to click on the back button to reach my page. I want this to be cleared. Also i need to clear the selection of the tree structure.
Hereby attaching the code while printing.
MemoryStream ms = new MemoryStream();
var urlPdf = Server.MapPath("~/Pdf/pdfMerge/" + id + "Merge_doc.pdf");
PdfReader ps = new PdfReader(urlPdf);//1
PdfStamper pdf = new PdfStamper(ps, ms);//2
pdf.JavaScript = "this.print({bUI: true,bSilent:false,bShrinkToFit: true});" + "\r\n" + "this.closeDoc();";//3
pdf.Close();//4
HttpContext.Current.Response.ClearContent();//5
HttpContext.Current.Response.ClearHeaders();//6
HttpContext.Current.Response.ContentType = "application/pdf";//7
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=quickforms.pdf");//8
HttpContext.Current.Response.BinaryWrite(ms.ToArray());//9
ms.Flush();
Can anybody help me?
Use
--kiosk --kiosk-printing <application_URL>
Create a new chrome.exe shortcut
Add –kiosk –kiosk-printing flags to the chrome.exe target shortcut
Add the url of the kiosk as the starting page in Chrome settings (or replace chrome.exe with “chrome.exe –kiosk http:// [enter URL here]”)
Drag the shortcut into the startup folder so it loads automatically.
That’s it! Then when you open it’s fullscreen and locked down with the kiosk and auto printing functionality all in one! :) To quit the Kiosk, press Alt + F4 on your keyboard.
MUST USE:
PRINT DIRECT: --kiosk-printing
KIOSK MODE: --kiosk [application_url]
KIOSK MODE & PRINT DIRECT: --kiosk-printing --kiosk [application_url]

Anguilla - Get the version and user information

I have created a command button on the Ribbon Toolbar. When I select an component an click on "Display Info" button, an popup should open telling me about the latest version of the Component, Modified date, and the User who last modified it.
I do get the component with the following code:
var item = $models.getItem(selection.getItem(0));
How can I get the other information from here.
Part 2:
When I try to see the JS code in Firebug, I see them in one single line. I am unable to put an break point on the execute function within my code.
Any suggestions on the above points. ?
To deminify the JS, to allow you to add breakpoints, and also to allow you to use a JS console to inspect objects that are available, you can follow the instructions at http://code.google.com/p/tridion-2011-power-tools/wiki/DeactivateJSMinifier.
User information can be retrieved using the information at How to get the user Id of the currently logged user in Tridion?
I find that the only way to find anything with Anguilla is to use a JS Console like Chrome's.
Once you get the current item - like you do now - you can do stuff like:
var version = item.getVersion();
var lastModifiedDate = item.getLastModifiedDate();
var lastEditorId = item.getStaticRevisorId();
getStaticRevisorId() gives you the Tridion URI of the last user to change the item, and you can then load this to retrieve further information from it.

How to Right click of File in Windows Explorer by AutoIt

I wish to simulate a right click on a file. This is done by opening a Windows Explorer window and then right clicking on it.
The main issue is finding the location of the file in Windows Explorer. I am currently using Autoit v3.3.8.1.
My code 's first line:
RunWait (EXPLORER.EXE /n,/e,/select,<filepath>)
The next step is the problem. Finding the coordinates of the file.
After that, right clicking at that coordinates (it seems to me at this time) is not a problem....
Some background:
OS: Windows 7 64-bit
Software Languages: C#, Autoit (for scripting)
The Autoit script is called by a code similar to that below:
Process p = new Process();
p.StartInfo.FileName = "AutoItScript.exe";
p.StartInfo.UseShellExecute = false;
p.Start();
The code is compiled into a console class file which is run at startup. The autoit script runs as the explorer window opens up.
It seems as though you are taking the wrong approach to the problem, so I'll answer what you are asking and what you should be asking.
First up though, that line of code is not valid, and is not what you want either. You want to automate the explorer window, and RunWait waits for the program to finish. Furthermore you want those items to be strings, that code would never work.
Finding the item in explorer
The explorer window is just a listview, and so you can use normal listview messages to find the coordinates of an item. This is done most simply by AutoIt's GUIListView library:
#include<GUIListView.au3>
Local $filepath = "D:\test.txt"
Local $iPid = Run("explorer.exe /n,/e,/select," & $filepath)
ProcessWait($iPid)
Sleep(1000)
Local $hList = ControlGetHandle("[CLASS:CabinetWClass]", "", "[CLASS:SysListView32; INSTANCE:1]")
Local $aClient = WinGetPos($hList)
Local $aPos = _GUICtrlListView_GetItemPosition($hList, _GUICtrlListView_GetSelectedIndices($hList))
MouseClick("Right", $aClient[0] + $aPos[0] + 4, $aClient[1] + $aPos[1] + 4)
As has already been mentioned, sending the menu key is definitely a better way than having to move the mouse.
Executing a subitem directly
This is how it should be done. Ideally you should never need an explorer window open at all, and everything can be automated in the background. This should always be what you aim to achieve, as AutoIt is more than capable in most cases. It all depends on what item you want to click. If it is one of the first few items for opening the file in various programs, then it is as simple as either:
Using ShellExecute, setting the verb parameter to whatever it is you want to do.
Checking the registry to find the exact command line used by the program. For this you will need to look under HKCR\.ext where ext is the file extension, the default value will be the name of another key in HKCR which has the actions and icon associated with the filetype. This is pretty well documented online, so google it.
If the action is not one of the program actions (so is built into explorer) then it is a little more complex. Usually the best way will be to look at task manager when you start the program and see what it runs. Other things can be found online, for example (un)zipping. Actions like copy, delete, rename, create shortcut, send to... They can all be done directly from AutoIt with the various File* functions.
With more information, it would be possible to give you more specific help.
First, you might want to look at the Microsoft Active Accessibility SDK. In particular look at this interface...
http://msdn.microsoft.com/en-us/library/accessibility.iaccessible.aspx
You can use this to walk the items in the control and find the one with the file name you are looking for and its screen location.
From there, maybe try something like this for simulating the right click.
How can I use automation to right-click with a mouse in Windows 7?
Once you have done the right click, use accessibility again to find the right option on the context menu.
Maybe there's an easier way, you should be able to cobble something together like this if you don't find one. Good luck!
Suppose I have a file named test.txt on D drive. It needs to right click for opening Context Menu. To do this, the following code should work:
Local $filepath = "D:\test.txt"
Local $iPid = Run("explorer.exe /n,/e,/select," & $filepath)
ProcessWait($iPid)
Sleep(1000)
Send('+{F10}')

Python selecting a value in a combo box and HTTP POST

In Python, I'm trying to read the values on http://utahcritseries.com/RawResults.aspx. How can I read years other than the default of 2002?
So far, using mechanize, I've been able to reference the SELECT and list all of its available options/values but am unsure how to change its value and resubmit the form.
I'm sure this is a common issue and is frequently asked, but I'm not sure what I should even be searching for.
So how about this:
from mechanize import Browser
year="2005"
br=Browser()
br.open("http://utahcritseries.com/RawResults.aspx")
br.select_form(name="aspnetForm")
control=br.form.find_control("ctl00$ContentPlaceHolder1$ddlSeries")
control.set_value_by_label((year,))
response2=br.submit()
print response2.read()
With problems relating to AJAX-loading of pages, use Firebug!
Install and open Firebug (it's a Firefox plugin), go to the Net page, and make sure "All" is selected. Open the URL and change the select box, and see what is sent to the server, and what is received.
It seems the catchily-named field ctl00$ContentPlaceHolder1$ddlSeries is what is responsible.. Does the following work..?
import urllib
postdata = {'ctl00$ContentPlaceHolder1$ddlSeries': 9}
src = urllib.urlopen(
"http://utahcritseries.com/RawResults.aspx",
data = urllib.urlencode(postdata)
).read()
print src

Resources