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

1.目标

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

2.操作环境
  • iPhone一台

  • WebDriverAgent

  • mac 安装 Xcode

3.流程

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

web-driver-agent_appium-实现自动点击+滑动屏幕https://ccccc.blog.csdn.net/article/details/134053551

界面输入文本 api

objectivec 复制代码
[[FBRoute POST:@"/wda/keys"] respondWithTarget:self action:@selector(handleKeys:)],




+ (id<FBResponsePayload>)handleKeys:(FBRouteRequest *)request
{
  NSString *textToType = [request.arguments[@"value"] componentsJoinedByString:@""];
  NSUInteger frequency = [request.arguments[@"frequency"] unsignedIntegerValue] ?: [FBConfiguration maxTypingFrequency];
  NSError *error;
  if (![FBKeyboard typeText:textToType frequency:frequency error:&error]) {
    return FBResponseWithStatus([FBCommandStatus invalidElementStateErrorWithMessage:error.description
                                                                           traceback:nil]);
  }
  return FBResponseWithOK();
}

实现源码

objectivec 复制代码
+ (BOOL)typeText:(NSString *)text error:(NSError **)error
{
  return [self typeText:text frequency:[FBConfiguration maxTypingFrequency] error:error];
}

+ (BOOL)typeText:(NSString *)text frequency:(NSUInteger)frequency error:(NSError **)error
{
  __block BOOL didSucceed = NO;
  __block NSError *innerError;
  [FBRunLoopSpinner spinUntilCompletion:^(void(^completion)(void)){
    [[FBXCTestDaemonsProxy testRunnerProxy]
     _XCT_sendString:text
     maximumFrequency:frequency
     completion:^(NSError *typingError){
       didSucceed = (typingError == nil);
       innerError = typingError;
       completion();
     }];
  }];
  if (error) {
    *error = innerError;
  }
  return didSucceed;
}

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

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

获取手机屏幕信息

objectivec 复制代码
+(void)window_size{
    
        
    NSLog(@"开始window_size: %@",@"-------------------");
    NSString* url = @"";
    url = [NSString stringWithFormat:@"http://127.0.0.1:8100/session/%@/window/size",iPhoneSessionId];
    
    [xddHttp reqWithMethodxdd2:url Method:0 HTTPBody:@"" Block:^(NSURLResponse *  response, NSDictionary *  data) {
        NSLog(@"window_size结果: %@",data);
//        [0]    (null)    @"width" : (long)414
//        [1]    (null)    @"height" : (long)736
        
        iPhoneWidth  = [data[@"value"][@"width"] longLongValue];
        iPhoneHeight = [data[@"value"][@"height"] longLongValue];
        
    }];
    
}

调用输入

objectivec 复制代码
+(void)element_value:(NSString*)text
{
    NSLog(@"开始输入: %@",@"-------------------");
    NSString* url = @"";
    url = [NSString stringWithFormat:@"http://127.0.0.1:8100/session/%@/element/38CB6A3B02B28FAFB0754B03D12AA7646ACEA558/value2",iPhoneSessionId];//1
   // url = [NSString stringWithFormat:@"http://127.0.0.1:8100/session/%@/wda/keys",iPhoneSessionId];//2
    NSString*body = @"";
    body = @"{\"text\":\"123好hao\"}";//1
    body = @"{\"value\":[\"123好hao\\r\\n\"],\"frequency\":10}";//2
    
    body = [NSString stringWithFormat:@"{\"text\":\"%@\"}",text];
    
    [xddHttp reqWithMethodxdd2:url Method:1 HTTPBody:body Block:^(NSURLResponse * _Nonnull response, NSDictionary * _Nonnull data) {
        NSLog(@"输入结果: %@",data);
    }];
}

+(void)element_value{
    [self element_value:@"123好hao"];
}

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

objectivec 复制代码
+(void)myTimers{
    userarr = [self testArr];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // 在这里执行你的任务
        //[self goo:nil];
    });
    
    myTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(goo:) userInfo:nil repeats:YES];
    
}

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

objectivec 复制代码
+(void)goo:(NSTimer *)timer{
    
    NSString*msgText = [xddCode getinfo:@"sendText"];
    NSString*msgTextKu = userarr[sendCount];
    NSString*text = [NSString stringWithFormat:@"%@%@\\r",msgText,msgTextKu];
    
    myAlertController.message=[NSString stringWithFormat:@" [%d / %lu] %@_%@",(sendCount+1),(unsigned long)userarr.count,msgText,msgTextKu];
    sendCount = sendCount + 1;
    NSString*url = [NSString stringWithFormat:@"http://127.0.0.1:8100/session/%@/wda/touch/perform",iPhoneSessionId];
    NSString*body = @"";
    body = @"{\"actions\":[{\"action\":\"tap\",\"options\":{\"x\":131,\"y\":248}}]}";//点击
    body = @"{\"actions\":[{\"action\":\"tap\",\"options\":{\"x\":131,\"y\":248}}]}";//点击
    body = [NSString stringWithFormat:@"{\"actions\":[{\"action\":\"tap\",\"options\":{\"x\":50,\"y\":%ld}}]}",iPhoneHeight-50];
    
    [xddHttp reqWithMethodxdd2:url Method:1 HTTPBody:body Block:^(NSURLResponse *  response, NSDictionary *  data) {
        NSLog(@"点击结果: %@",data);
        NSString*msgTextKu = userarr[sendCount];
        NSString*text = [NSString stringWithFormat:@"%@%@%@\\r",msgText,msgTextKu,[xddCode getTime:@"ss"]];
        
        [self element_value:text];//输入文字
    }];
    
}

实现效果

https://live.csdn.net/v/340697https://live.csdn.net/v/340697

web-driver-agent_appium自动输入

相关推荐
HABuo5 小时前
【linux文件系统】磁盘结构&文件系统详谈
linux·运维·服务器·c语言·c++·ubuntu·centos
Howrun7775 小时前
关于Linux服务器的协作问题
linux·运维·服务器
yunfuuwqi7 小时前
OpenClaw✅真·喂饭级教程:2026年OpenClaw(原Moltbot)一键部署+接入飞书最佳实践
运维·服务器·网络·人工智能·飞书·京东云
迎仔7 小时前
C-算力中心网络隔离实施方法:怎么搞?
运维·网络
代码游侠7 小时前
C语言核心概念复习——网络协议与TCP/IP
linux·运维·服务器·网络·算法
AtoposのCX3309 小时前
Docker运行hello-world镜像失败或超时
运维·docker
熊延10 小时前
麒麟V10系统安装部署elasticsearch
linux·运维·服务器·elasticsearch·搜索引擎·全文检索
Yeats_Liao13 小时前
评估体系构建:基于自动化指标与人工打分的双重验证
运维·人工智能·深度学习·算法·机器学习·自动化
爱吃生蚝的于勒13 小时前
【Linux】进程信号之捕捉(三)
linux·运维·服务器·c语言·数据结构·c++·学习
文艺理科生Owen13 小时前
Nginx 路径映射深度解析:从本地开发到生产交付的底层哲学
运维·nginx