[英]How to click a button using html or java script which is declared as div
I am writing a powershell script to login to a website. 我正在编写Powershell脚本来登录网站。 I want to use the button.click functionality but I can't find the button's id.
我想使用button.click功能,但是找不到按钮的ID。 here is what I found by inspecting it.
这是我通过检查发现的。
<div tabindex="0" role="button" class="v-button v-widget default v-button-default">
<span class="v-button-wrap">
<span class="v-button-caption">Login</span>
</span>
</div>
<span class="v-button-wrap">
<span class="v-button-caption">Login</span>
</span>
<span class="v-button-caption">Login</span>
Thanks in advance 提前致谢
Given that you aren't sure which one is the one you want, you could just set up an event handler that will trigger for each and then interrogate it for something that can identify it. 鉴于您不确定要使用的是哪个,可以设置一个事件处理程序,该事件处理程序将为每个事件触发,然后对其进行询问以识别出它。
// Get all the elements with a class of "v-button-caption" into an array var buttons = Array.prototype.slice.call(document.querySelectorAll(".v-button-caption")); // Loop over the array buttons.forEach(function(btn){ // Set up a click event handler btn.addEventListener("click", function(evt){ // Print out some identifying information about the clicked element console.log("You clicked the element who's parent is: " + evt.target.parentElement.nodeName); }); });
<div tabindex="0" role="button" class="v-button v-widget default v-button-default"> <span class="v-button-wrap"> <span class="v-button-caption">Login</span> </span> </div> <span class="v-button-wrap"> <span class="v-button-caption">Login</span> </span> <span class="v-button-caption">Login</span>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.