抖店达人邀请页面,对页面元素进行模拟点击操作

javascript
ar add_dom = document.getElementById("portal")
var new_dom = document.createElement("iframe")
new_dom.id = 'gz';
new_dom.style = 'width:100%; height:600px;'
new_dom.src = "https://buyin.jinritemai.com/dashboard/servicehall/daren-profile?uid=d8c794265cc7e83b724e97f82ff11811";
add_dom.append(new_dom);

var dom_index = 0
var dom ;
var uid = []
var is_ok = true


function handle_yaoyue(){
    console.log("发送邀约")
    var kj = document.getElementById("gz").contentWindow.document;
    kj.getElementsByClassName("auxo-btn    auxo-btn-primary contact-btn-container-button")[0].click()
setTimeout(function(){kj.getElementsByClassName("text4 add-product-last-operate")[0].click()},)
setTimeout(function(){kj.getElementsByClassName("auxo-btn auxo-btn-primary")[0].click()},)

}
执行到auxo-btn auxo-btn-primary时,只会点击添加商品这里
怎么才能让他只点击 发送邀约

img

img

可以给这2个按钮写不同的ID,通过ID去绑定点击事件即可

获取.auxo-drawer-footer 元素内的 .auxo-btn.auxo-btn-primary 即可

setTimeout(function(){kj.querySelector(".auxo-drawer-footer .auxo-btn.auxo-btn-primary").click()},)

或者下标[0]改成[1], 点击获取相同class的第二个按钮

setTimeout(function(){kj.getElementsByClassName("auxo-btn auxo-btn-primary")[1].click()},)

可以把这句代码let children = kj.getElementsByClassName("auxo-btn auxo-btn-primary")在控制台 把children console出来看看,你会看到整个元素源码都打印出来一层一层结构的,这样就可以通过childrenNode(记得大概是这个属性名称样子)和下标索引随便找到你要的元素来click或其他操作了

通过iframe这种方式可能会出现这种获取不到元素的情况
建议你使用油猴脚本之类的浏览器插件操作

用这个查看一下 是不是这个标签,

console.log(kj.getElementsByClassName("text4 add-product-last-operate")[0].innerHTML)

如果不是 遍历找出 对应的标签 才能实现这个事件

let arr=kj.getElementsByClassName("text4 add-product-last-operate");
for(let i=0;i<arr.length;i++){
  if(arr[i].innerHTML=='发出邀约'){
    arr[i].click();
    break;
   }
}

如果还没解决 可以远程