简体   繁体   中英

You cannot call a method on a null-valued expression. clicking button in webpage via powershell

I am trying to click a button within a synology nas webpage environment. Sadly the $link=$ie.Document.getElementByID('ext-gen258') $linck.click()

doesn't work as the element id constantly changes when you reload the page.

The element im trying to open:

<div class="item-wrap" id="ext-gen1413" role="button" aria-labelledby="controlpanel:leaf_security" cate="tree:node_connection" fn="SYNO.SDS.AdminCenter.Security.Main">
    <div class="icon-image syno-app-admin-center-icon-image" style='background-image: url("webman/modules/AdminCenter/images/default/1x/home_icons/security.png?v=25426-s2");'></div>
    <div class="text" id="controlpanel:leaf_security">Beveiliging</div>
</div>

I also tried the following code:

$button = $ie.Document.getElementsByTagName("div") | 
          Where-Object {$_.value -eq "controlpanel:leaf_security"}

$button.click()

But then the code wont resume and get stuck. What am I doing wrong?

$doc = $ie.document

# commit the button
$commit = $doc.getElementById("controlpanel:leaf_security")
if ($commit) { $commit.click() } 

this code works... dont know why tho would love to have a explanation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM