我正在尝试自动执行目录同步过程。基本上我需要登录该站点,搜索用户,然后单击编辑以更改三个设置,但由于某种原因我无法使PowerShell单击编辑。 <a href="/User/Details
或><a href="/User/Edit/
永远不会更改,但其余内容会因用户而异。
<td>domain.com.com/OU/lastname, firstname</td>
<td>username</td>
<td>firstname</td>
<td></td>
<td>Pinar</td>
<td></td>
<td>00334764</td>
<td>8/1/2012 5:53:45 PM</td>
<td><a href="/User/Details/sajskjdf-ajsjkf-asddd">Details</a></td>
<td><a href="/User/Edit/sajskjdf-ajsjkf-asddd">Edit</a></td>
</tr>
到目前为止,这是我的代码:
#login to site
$url = "https://website"
$username = 'username'
$password = read-host "password"
$ie = New-Object -com internetexplorer.application;
$ie.visible = $true;
$ie.navigate($url);
while ($ie.Busy -eq $true)
{
Start-Sleep -Milliseconds 100;
}
$ie.Document.getElementById("username").value = $username
$ie.Document.getElementById("Password").value = $password
$go = $ie.Document.getElementsByTagName(‘button’) | where-object {$_.type -eq ‘submit’}
$go.click()
while($ie.Busy) {Start-Sleep 1}
# Enter the username you want to edit
$logonname=read-host "logonname"
$ie.Document.getElementById("query").value = $logonname
$go2 = $ie.Document.getElementsByTagName(‘button’) | where-object {$_.type -eq ‘submit’}
$go2.click()
while($ie.Busy) {Start-Sleep 1}
# I can't make this part work :(
$go3 = $ie.Document.getElementsByTagName(‘A’)
$yt = $go3 | where-object {$_.innerText -eq '/Edit/User/'}
$yt.click()
答案 0 :(得分:2)
以下是点击特定链接的示例:
$ie = New-Object -ComObject InternetExplorer.Application
$ie.visible=$true
$ie.navigate2('http://google.com/')
while($ie.Busy) {Start-Sleep 1}
$links = $ie.Document.getElementsByTagName('A')
$yt = $links | where {$_.innerText -eq 'YouTube'}
$yt.click()