sl4a dialogCreateDatePicker() - sl4a

How can I close dialogCreateDatePicker()? After using button screen is inactive and black.
My example:
import sl4a
droid = sl4a.Android()
droid.dialogCreateDatePicker()
droid.dialogShow()

You can close it with:
droid.dialogDismiss()

Related

Selenium Webdriver - Keys not being sent to search boxes

I am starting to use Selenium Webdriver (Chrome) and while pages open automatically keys are not being sent for some reason. For example, I open google.com, and I use a "BY.ID" to aim at the search box by it's ID and send "Hi" but for some reason, it doesn't send the keys, I tried looking at the Selenium documentation but It kinda left me more confused, anybody knows why keys aren't being sent? Thanks in advance!
from selenium import webdriver
from selenium.webdriver.common.by import By
browser = webdriver.Chrome('/Users/thras/Desktop/Chromedriver/chromedriver')
browser.get('https://www.youtube.com')
title = browser.title
browser.implicitly_wait(3)
text_box = browser.find_element(By.ID,"search").send_keys('Hi')
from selenium import webdriver
from selenium.webdriver.common.by import By
browser = webdriver.Chrome('/Users/thras/Desktop/Chromedriver/chromedriver')
browser.get('https://www.google.com')
title = browser.title
browser.implicitly_wait(3)
text_box = browser.find_element(By.NAME, value="q")
text_box.send_keys('Hiii')
fixed, it was syntax issue it seems, I needed to add "value" before the actual ID

defaultSourceDPIInt in the default theme.css of CodenameOne

In the new Codename One bare-bones project (https://start.codenameone.com/), there is a default theme.css that starts with:
#Constants {
includeNativeBool: true;
defaultSourceDPIInt: "0";
}
What is defaultSourceDPIInt: "0";? I couldn't find anything in the blog about this.
It's discussed here: https://www.reddit.com/r/cn1/comments/p0utte/defaultsourcedpiint_css_theme_constant_can_make/
The defaultSourceDPIInt constant which you can use as:
#Constants {
/* ... */
defaultSourceDPIInt: 0;
}
Sets the default DPI of images you use in the theme. This is very
important as the default is the creation of multi images. With 0 we're
essentially importing all images as regular images by default which
means you need to explicitly state the source DPI to prevent mistakes.
Check out the git commit for the full story:
https://github.com/codenameone/CodenameOne/commit/f31fb8a046759ed884ab61b2d34b42a614b2dbd2

Taking a screenshot of a remote desktop using Sikuli

I have the following Java code which I am using to capture a screenshot:
import org.sikuli.script.Screen;
import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
public class Screenshot{
public static void main(String[] args) throws IOException
{
Screen screen = new Screen();
ImageIO.write(screen.capture(screen).getImage(), "png", new File("D:\\myScreen.png"));
}
}
I compile the piece of code using:
javac -classpath .;sikulixapi-2.0.4.jar Screenshot.java
and run it with:
java -classpath .;sikulixapi-2.0.4.jar Screenshot
I tried to run it remotely, using
psexec \\xx.xx.xxx.xxx -w "D:\Sikuli" java -classpath .;sikulixapi-2.0.4.jar Screenshot
The result is not the picture of the remote screen, but only a black background.
Is there any way to make this work?
To check wether you principally could get a shot of the remote screen this way, you can use what SikuliX uses internally: java.awt.Robot
try this:
import java.awt.*;
...
BufferedImage img = new Robot().createScreenCapture(new Rectangle(0, 0, 500, 500))
... and then your coding to store the image somewhere.
If the image is black, then you have a problem with the monitor setup on the remote system. It must be non-headless (real screen) and Robot must have access to an unlocked screen.
RaiMan from SikuliX

AndroidX Preferences and Navigation

Are there any examples of using the Jetpack / androidx preference library alongside the navigation component / Single activity? All the examples I'm seeing ( e.g. Google's example ) are using supportFragmentManager and replacing the content of a FrameLayout.
Navigating to the PreferenceFragmentCompat() with the navigation component almost works, in that it shows the Preferences page, but it is missing all of the toolbar/navigation icons. It's just implanted over the previous fragment, so to exit it, you need to hit the hardware back button.
Looks like this already has an issue filed with Google's issue tracker here
I just ran into the same problem and this is how I implemented it. Before I get into the code I want to give a quick summary. I have a single activity and two fragments. One of the fragments is the main fragment that is the home screen for the application and the other is the fragment that shows the settings. I end up not using SupportFragmentManager (which Google shows in their settings guide) as I was running into the same problem where the view would just appear on top of the previous view. So I just navigate to the settings fragment in the same way you would navigate to any other fragment in the single activity architecture using findNavController().navigate(...).
Firstly you will need to add the appropriate dependencies to your app build.gradle:
dependencies {
...
// androidx Preferences
implementation "androidx.preference:preference-ktx:1.1.0"
// androidx Navigation
implementation 'androidx.navigation:navigation-fragment-ktx:2.2.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.2.0'
Then I set up my MainActivity.kt for Navigation as described in Google's navigation guide
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
NavigationUI.setupActionBarWithNavController(
this, this.findNavController(R.id.nav_host_fragment)
)
}
// Allows the up arrow to navigate back to the navigation host fragment.
override fun onSupportNavigateUp(): Boolean {
return Navigation.findNavController(this, R.id.nav_host_fragment).navigateUp()
}
}
After that, set up a fragment that will be hosted by MainActivity.kt. This fragment is what will appear when you open up your app. I call mine MainFragment.kt. See Google's menu guide for help on creating the dropdown menu that is inflated when the three dot icon in the toolbar is clicked.
class MainFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Show the three dot icon in the top right had corner of the toolbar
setHasOptionsMenu(true)
return inflater.inflate(R.layout.fragment_main, container, false)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
// Navigate to the settings fragment when the options menu item is selected
R.id.settings -> {
findNavController().navigate(MainFragmentDirections.actionMainToSettings())
true
}
else -> super.onOptionsItemSelected(item)
}
}
// Inflates menu.xml when the three dot icon is clicked
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.menu, menu)
}
}
Finally, the settings fragment is pretty easy to implement. Reference Google's settings guide (see link above) on how to set that up.
class MySettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.preferences, rootKey)
}
}
Also, don't forget to hook up your fragments in nav_graph.xml. Reference Google's navigation guide linked above for examples of that.
Hope this helps!

Handle browser dialog window without focus

I have a Selenium WebDriver based script to automate file uploading. It uploads list of files one by one. I use AutoIT script to handle dialog window, file chooser window. Parameter $CmdLine[1] contains the path of actual file.
ControlFocus("Open a file","","Edit1")
ControlSetText("Open a file","","Edit1", $CmdLine[1])
ControlClick("Open a file","","Button1")
I execute it from Java code as following:
Runtime.getRuntime().exec(autoITExecutable);
It opens dialog window, so it can't work without focus on browser window.
File upload field works like this demo:
https://encodable.com/uploaddemo/
I ran simple script for the link you gave and it works great
import os
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://encodable.com/uploaddemo/")
driver.find_element_by_name("uploadname1").send_keys(os.getcwd() + "/test.csv")
driver.find_element_by_name("email_address").send_keys("none#getnada.com")
driver.find_element_by_name("first_name").send_keys("Tarun")
driver.find_element_by_id("uploadbutton").click()
Try your code in similar format as shown below and try:
WinWaitActive("File Upload") // enter the title of the pop up
Send("Path of the file to enter") // enter the path of the file to upload
Send("{ENTER}") / press enter

Resources