Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make a phone call with Python

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the knowledge of "how to use Python to make a phone call". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

I. Environmental configuration

1. Install jdk 1.8 + with environment variables.

2. To install Android SDK, you can download and install it directly, or install it through android-studio. Install the environment variables after installation, and enter adb after the cmd to execute successfully.

3. Install appium 1.8.0, the version I use is quite stable, native and Wechat H5 support is OK, some other versions have been tried, maybe native support is OK, Wechat official account H5 page support is not friendly.

Second, view the elements

After sdk is installed, find uiautomatorviewer.bat to open and use to get element id, text and other attributes for us to locate elements. This is basically the same as selenium's set, but it is worth noting that id in Android app is not unique. This is different from that in web. When using id, pay attention to whether it is the only element.

Using the tool in the upper-left corner to examine elements, such as the * key, you can see that id is star, while other keys view various elements in the same way as id.

III. Acquisition of configuration information

1. The computer and mobile phone are connected through the data cable. Enter the command adb devices to obtain the device identification number of the mobile phone.

2. Command line input: adb shell dumpsys window windows | findstr "Current"

Used to get the package name and startup page of the current application.

Package name: com.android.contacts

Launch page: com.android.contacts.activities.TwelveKeyDialer

IV. Code writing

The code is as follows, I have the relevant introduction file here.

Import syssys.path.insert (0 "C:\\ Users\\ Administrator\\ Desktop\\ imooc\\ python_call") from action import Actionfrom appium import webdriveraction = Action () # related configuration action.desired_caps ['platformName'] =' Android' # platform action.desired_caps ['platformVersion'] =' 7.0' # Android version action.desired_caps ['deviceName'] =' a20bc6990604'# device number action.desired_caps ['appPackage'] =' com.android.contacts' # Package name action.desired_caps ['appActivity'] =' com.android.contacts.activities.TwelveKeyDialer' # Startup Page action.desired_caps ['unicodeKeyboard'] = True # sends the string action.desired_caps [' resetKeyboard'] = True # using unicode encoding to hide the keyboard Default trueaction.desired_caps ['noReset'] = True # whether the application status needs to be reset, default trueaction.desired_caps [' automationName'] = 'Uiautomator2' # automation engine Compatible with native and hash control remote appiumaction.driver = webdriver.Remote ("http://127.0.0.1:4723/wd/hub", Action.desired_caps) # Click event action.click_key ("id= > one") action.click_key ("id= > five") action.click_key ("id= > two") action.click_key ("id= > three") action.click_key ("id= > six") action.click_key ("id= > two") action.click_key ("id= > eight") action.click_key ("id= > star") action.click_key ("id= > star") ") action.click_key (" id= > call_sim1 ")

Click_key is my custom method, for example, after passing in id= > star, split is divided according to = >. There is id in front and id value in the back. Sometimes I will write it in xpath. In fact, I am involved in a lot of variables in the project, many of which are maintained separately. You may look a little complicated, but in fact, you are similar to selenium. The click method is click, and the element is find_element. Then, if you look for it according to id, you need to pass in the id value.

ByDict = {"xpath": By.XPATH, "id": By.ID,} def find_ele (self, loc): print (loc.split ("= >") [0], loc.split ("= >") [1]) element = WebDriverWait (self.driver, 30). Until (lambda x: x.find_element (byDict [loc.split ("= >") [0], loc.split ("= >") [1]) print (element) return elementdef click_key (self) Loc): self.find_ele (loc). Click ()

V. Operation

Start appium, start it with the default of 0.0.0.0 4723, then run the python program, and you can see the execution process of phone calls.

This is the content of "how to use Python to make a phone call". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 241

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report