• 【iOS免越狱】利用IOS自动化WebDriverAgent实现自动直播间自动输入


    1.目标

    由于看直播的时候主播叫我发 666,支持他,我肯定支持他呀,就一直发,可是后来发现太浪费时间了,能不能做一个直播间自动发 666 呢?于是就开始下面的操作。

    2.操作环境
    • iPhone一台

    • WebDriverAgent

    • mac 安装 Xcode

     3.流程

    首先安装WebDriverAgent ,安装教程请看上一篇

    web-driver-agent_appium-实现自动点击+滑动屏幕icon-default.png?t=N7T8https://ccccc.blog.csdn.net/article/details/134053551

     界面输入文本 api

    1. [[FBRoute POST:@"/wda/keys"] respondWithTarget:self action:@selector(handleKeys:)],
    2. + (id)handleKeys:(FBRouteRequest *)request
    3. {
    4. NSString *textToType = [request.arguments[@"value"] componentsJoinedByString:@""];
    5. NSUInteger frequency = [request.arguments[@"frequency"] unsignedIntegerValue] ?: [FBConfiguration maxTypingFrequency];
    6. NSError *error;
    7. if (![FBKeyboard typeText:textToType frequency:frequency error:&error]) {
    8. return FBResponseWithStatus([FBCommandStatus invalidElementStateErrorWithMessage:error.description
    9. traceback:nil]);
    10. }
    11. return FBResponseWithOK();
    12. }

     

    实现源码

    1. + (BOOL)typeText:(NSString *)text error:(NSError **)error
    2. {
    3. return [self typeText:text frequency:[FBConfiguration maxTypingFrequency] error:error];
    4. }
    5. + (BOOL)typeText:(NSString *)text frequency:(NSUInteger)frequency error:(NSError **)error
    6. {
    7. __block BOOL didSucceed = NO;
    8. __block NSError *innerError;
    9. [FBRunLoopSpinner spinUntilCompletion:^(void(^completion)(void)){
    10. [[FBXCTestDaemonsProxy testRunnerProxy]
    11. _XCT_sendString:text
    12. maximumFrequency:frequency
    13. completion:^(NSError *typingError){
    14. didSucceed = (typingError == nil);
    15. innerError = typingError;
    16. completion();
    17. }];
    18. }];
    19. if (error) {
    20. *error = innerError;
    21. }
    22. return didSucceed;
    23. }

    方法已经找到,开始调用他

    自己写一个 app,安装到手机

    获取手机屏幕信息

    1. +(void)window_size{
    2. NSLog(@"开始window_size: %@",@"-------------------");
    3. NSString* url = @"";
    4. url = [NSString stringWithFormat:@"http://127.0.0.1:8100/session/%@/window/size",iPhoneSessionId];
    5. [xddHttp reqWithMethodxdd2:url Method:0 HTTPBody:@"" Block:^(NSURLResponse * response, NSDictionary * data) {
    6. NSLog(@"window_size结果: %@",data);
    7. // [0] (null) @"width" : (long)414
    8. // [1] (null) @"height" : (long)736
    9. iPhoneWidth = [data[@"value"][@"width"] longLongValue];
    10. iPhoneHeight = [data[@"value"][@"height"] longLongValue];
    11. }];
    12. }

     调用输入

    1. +(void)element_value:(NSString*)text
    2. {
    3. NSLog(@"开始输入: %@",@"-------------------");
    4. NSString* url = @"";
    5. url = [NSString stringWithFormat:@"http://127.0.0.1:8100/session/%@/element/38CB6A3B02B28FAFB0754B03D12AA7646ACEA558/value2",iPhoneSessionId];//1
    6. // url = [NSString stringWithFormat:@"http://127.0.0.1:8100/session/%@/wda/keys",iPhoneSessionId];//2
    7. NSString*body = @"";
    8. body = @"{\"text\":\"123好hao\"}";//1
    9. body = @"{\"value\":[\"123好hao\\r\\n\"],\"frequency\":10}";//2
    10. body = [NSString stringWithFormat:@"{\"text\":\"%@\"}",text];
    11. [xddHttp reqWithMethodxdd2:url Method:1 HTTPBody:body Block:^(NSURLResponse * _Nonnull response, NSDictionary * _Nonnull data) {
    12. NSLog(@"输入结果: %@",data);
    13. }];
    14. }
    15. +(void)element_value{
    16. [self element_value:@"123好hao"];
    17. }

     开启定时器,实现自动发送

    1. +(void)myTimers{
    2. userarr = [self testArr];
    3. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    4. // 在这里执行你的任务
    5. //[self goo:nil];
    6. });
    7. myTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(goo:) userInfo:nil repeats:YES];
    8. }

     点击屏幕的输入框,然后输入文字

    1. +(void)goo:(NSTimer *)timer{
    2. NSString*msgText = [xddCode getinfo:@"sendText"];
    3. NSString*msgTextKu = userarr[sendCount];
    4. NSString*text = [NSString stringWithFormat:@"%@%@\\r",msgText,msgTextKu];
    5. myAlertController.message=[NSString stringWithFormat:@" [%d / %lu] %@_%@",(sendCount+1),(unsigned long)userarr.count,msgText,msgTextKu];
    6. sendCount = sendCount + 1;
    7. NSString*url = [NSString stringWithFormat:@"http://127.0.0.1:8100/session/%@/wda/touch/perform",iPhoneSessionId];
    8. NSString*body = @"";
    9. body = @"{\"actions\":[{\"action\":\"tap\",\"options\":{\"x\":131,\"y\":248}}]}";//点击
    10. body = @"{\"actions\":[{\"action\":\"tap\",\"options\":{\"x\":131,\"y\":248}}]}";//点击
    11. body = [NSString stringWithFormat:@"{\"actions\":[{\"action\":\"tap\",\"options\":{\"x\":50,\"y\":%ld}}]}",iPhoneHeight-50];
    12. [xddHttp reqWithMethodxdd2:url Method:1 HTTPBody:body Block:^(NSURLResponse * response, NSDictionary * data) {
    13. NSLog(@"点击结果: %@",data);
    14. NSString*msgTextKu = userarr[sendCount];
    15. NSString*text = [NSString stringWithFormat:@"%@%@%@\\r",msgText,msgTextKu,[xddCode getTime:@"ss"]];
    16. [self element_value:text];//输入文字
    17. }];
    18. }

    实现效果

    https://live.csdn.net/v/340697icon-default.png?t=N7T8https://live.csdn.net/v/340697

    web-driver-agent_appium自动输入

  • 相关阅读:
    【路径规划】基于遗传算法求解立体仓库出入库路径优化问题含Matlab代码
    基于Android的教室预约系统
    cpu设计和实现(协处理器hi和lo)
    RobotFramework框架+Selenium实现UI自动化测试(十六)
    Django系列16-员工管理系统实战--echar图表统计
    Spring Security配置
    [ vulhub漏洞复现篇 ] struts2远程代码执行漏洞s2-016(CVE-2013-2251)
    excel导入poi中的数据使用cell.getStringCellValue()获取报错
    从Redis分布式缓存实战入手到底层原理分析、覆盖大厂面试考点
    初级C语言之【函数】
  • 原文地址:https://blog.csdn.net/qq_21051503/article/details/134200777