i wanted to enter some text to a text field in my android application.I installed the app and in the second page i wanted to search for some places.For that i need to enter some text.
I tried `device.press('KEYCODE_BUTTON_SELECT',MonkeyDevice.DOWN_AND_UP)
device.press('KEYCODE_i','DOWN_AND_UP')
device.press('KEYCODE_n','DOWN_AND_UP')
device.press('KEYCODE_d','DOWN_AND_UP')
device.press('KEYCODE_i','DOWN_AND_UP')
device.press('KEYCODE_a','DOWN_AND_UP')
or
Device.type(India)`
But these commands are not working for my application.,It is not entering string "India" to my application text filed.But this is working with phone native search text filed.
I installed Android View Client and import the following things
import from com.dtmilano.android.view client import View Client
from com.android.monkey runner import Monkey Runner, Monkey Device
Then i wrote the code like this
vc = ViewClient(device)
vc.dump()
address= vc.findViewById('search')
address.type('india')
But it is showing error: 'None Type' object has no attribute 'type'.
Can u pls help me in doing this.
You may want to use:
address = vc.findViewByIdOrRaise('search')
to avoid having to check for a not found address field.
Also, I guess the id is 'id/search'.
And finally a word of warning on:
address.type('india')
This is EditText.type() so you have to be sure that address is an EditText
print address.getClass()
otherwise you can use
address.touch() # to focus it
device.type('india')
or (because sometimes type() chokes)
address.touch() # to focus it
for c in 'india':
device.type(c)
Related
I am pretty new to web-scraping and recently I am trying to automatically scrap phone number for pages like this. I am not supposed to use Selenium/headless url browser libraries and I am trying to find the a way to actually request the phone number using let say a web service or any other possible solution that could give me the phone number hopefully directly without having to go through the actual button press by selenium.
I totally understand that it may not even be possible to automatically reveal the phone number in one shut as it is meant not be accessible by nosy newbie web-scraper like me; but I still like to raise the question for my information to get detailed answer from an expert point of view.
If I search the "Reveal" button DOM element, it shows some tags which I have never seen before. I have two main questions which I believe could be helpful for newbies like me.
1) Given a set of unknown tags/attribues (ie. data-q and data-reveal in the blow button), how is one able to find out which scripts in the page are actually using them?
2) I googled the button element's tag like: data-q and data-reveal the only relevant I could find was this which for some reason I don't have access two even-if I use proxy.
Any clue particularly on the first question is much appreciate it.
Regards,
Below is the href-button code
Reveal
Ok, according to your demand there are several steps before you finally get a solution.
1st step : open your own browser and enter your target page(https://www.gumtree.com/p/vans/2015-ford-transit-custom-2.2tdci-290-l1-h1/1190345514)
2nd step : (Assume you are using Chrome as your favorite browser) Press Ctrl+Shift+I to open the console, and then select 'Network' tag in the console.
3rd step : Press the 'Reveal' button on that page, watch the console carefully, catch the http request which is sent immediately when you press the 'Reveal' button. You can see the request contains a long string of number in Query String Parameters, actually it is a timestamp.
4th step : Also you can see there is a part named 'Request Headers' in that http request, and you should copy the values of referer , user-agent , x-gumtree-token.
5th step : Try to construct your request (I am a fan of Python, So I am going to show you my example code in Python)
import time
import requests
import json
headers = {
'referer': 'please enter the value you just copied from that specific request',
'user-agent': 'please enter the value you just copied from that specific request',
'x-gumtree-token': 'please enter the value you just copied from that specific request'
}
url = 'https://www.gumtree.com/ajax/account/seller/reveal/number/1190345514?_='
current_time = time.time()
current_time = str(current_time)
current_time = current_time.split('.')[0] + current_time.split('.')[1] + '0'
url += current_time
response = requests.get(url=url,headers=headers)
response_result = json.loads(response.content)
phone_number = response_result['data']
I followed this tutorial:
https://msdn.microsoft.com/en-us/library/windows/apps/hh202967(v=vs.105).aspx
It works, but the toast that appears on the phone screen contains all of this:
Received Toast 4:05 PM:
wp:Text1: Please
wp:Text2: Help!
wp.Param: /Page2.xaml?
NavigatedFrom=Toast Notification
I would like for the toast to only contain text1 and text2. In this instance I only want "Please Help!" to appear. I've looked at everything on MSDN and everywhere else on google and there is nothing on it.
You should see what you want if the demo app isn't running when the toast arrives: an alert with "Please Help!" will show at the top of the screen.
If the app is running then the app's ShellToastNotificationReceived event fires instead of the toast appearing on the phone. This lets the app decide what to show. The demo code parses the received data and explicitly adds each key and value to a string and shows it in a MessageBox. This is purely for demonstration. A real app would never do that.
Typically a real app would find the interesting information and display it in-line rather than in a MessageBox, but the details will depend on the app.
If you want to display the contents of wp:Text1 and wp:Text2 in a TextBlock you can create the string something like:
StringBuilder message = new StringBuilder();
message.AppendFormat("{0} {1}",e.Collection["wp:Text1"],e.Collection["wp:Text2"]);
MyTextBlock.Text = message;
In production you'd probably want to verify that wp:Text1 and wp:Text2 existed, etc.
So I'm trying to create a GUI that searches a dictionary for a word, returns the entries and suggestions and downloads the audio, returning "related words" (sometimes more than one) that have audio. Then, the user clicks on one of three buttons to play the audio, based on the dialect. I can get the words to play, but I can't get the last played one to close so I can download another.
Here is the relevant code:
#staticmethod
def munster():
""" This method plays the Munster recording, if it exists"""
url = QtCore.QUrl.fromLocalFile("./CanM.mp3")
content = QtMultimedia.QMediaContent(url)
player = QtMultimedia.QMediaPlayer()
player.setMedia(content)
player.play()
player.stateChanged(app.quit)
When it gets to the last line it gives me this error:
TypeError: native Qt signal is not callable
Is there any way to close the player to allow downloading of another audio file with the same name?
For the record, I'm using the latest release of PyQt5, and Qt5.4 on Python 3.4 with Windows 81. However, I'm also working on this project (with the same Qt and PyQt) on an Archlinux system as well, and would like it to be portable easily.
Edit: Quite easy, once I started looking at what all was contained within the Player class. Just needed to use the disconnect method.
Edit2: Edited to show complete working code
#staticmethod
def play_audio(dialect):
file_names = {'Munster': './CanM.mp3', 'Connacht': './CanC.mp3', 'Ulster': './CanU.mp3'}
url = QtCore.QUrl.fromLocalFile(os.path.abspath(file_names[dialect]))
content = QtMultimedia.QMediaContent(url)
player = QtMultimedia.QMediaPlayer()
player.setMedia(content)
player.play()
player.stateChanged.connect(lambda: player.disconnect())
I have a application window with two text fields (no access to the application code, so cant change anything). User scans a barcode in the fields, the action "enter press" is programmed in the scanner and cannot be changed. I need to validate the fields before enter is pressed, I can validate the first field but the issue is I need to validate the second field before enter is press(which is through the scanner). Is there a way this can be achieved using AutoIT? I hope the question make sense.
Use the "AutoIt v2 Window Info" tool (Au3Info.exe) to identify the two edit controls. On the "Control" tab you find the "Advanced Mode", which will show data like "[CLASS:Edit;INSTANCE:2]". Now use this information to read the data of the control:
$Text1 = ControlGetText('window title', '', '[CLASS:Edit; INSTANCE:1]')
$Text2 = ControlGetText('window title', '', '[CLASS:Edit; INSTANCE:2]')
See the example here: http://www.autoitscript.com/autoit3/docs/functions/ControlGetText.htm
most barcode scanners can be programmed to not send the terminator (enter) usually by scanning a couple special barcodes in the users manual
I program scanners with special terminators so our program can tell the input was from a scanner and not key presses
I am trying to run a test on selenium IDE to enter to my Gmail, select the specific new email from all my email enter and click on a specific link that the email has.
I've been going round and round this and cannot find and answer!
I have read another post that has this help:
//div[#class = 'y6']/span[contains(., 'subject here')]
This does not help because the same email has been sent lots of times.
This case has the following particularities:
1. Since is a case that it will be run several times, emails with the same sender, subject and body will be send.
There should only be one new email every time the test is fun, since the idea is to enter and check the last email.
Inside the email there is a button that needed to be press, which I have the id, but I just need to enter the email to do so.
I have used the following CSS that so far has found what i need to click, but when I ask Selenium IDE to click it, it does nothing (clickAt, clickAndWait, clickAtAndWait... nothing!)
css=div[class=yW] > span.zF:[email='myemail#myemail.com']
I have also notice that the class="zA zE" in Gmail indicates that the email has not yet been read.
Help!
Thanks,
This is strange, because clickAt | css=div.yW > span.zF[email='myemail#myemail.com'] works fine for me. More than that, clickAt | css=span[email='myemail#myemail.com'] will always open first message(last one) with this email in the list.
BarbSchael,
A similar solution can be drawn by using Xpath of the FROM field.
I used this command:
clickAt | //table/tbody/tr/td[5]/div[#class='yW'] |
Click at the FROM field of first/recent/top most mail to go to mail detail page. // note: tr for first mail, tr[2] for second and so on.