0

I am trying to automate the downloading of a csv file from a website. The submit button in the login form is the only succesful button clicked but the other buttons inside the page is not responding to the commands. here is my code enter image description here this is the html of the button I am trying to click by powershell script enter image description here

I already tried this codes

$btn = $IE.Document.getElementsByClassName('btn_schedule_search')  | Select-Object -First 1
$btn.Click()

$IE.Document.getElementsByClassName('btn_schedule_search').Click()

$IE.Document.querySelector('[class="btn_schedule_search"]').Click() 

$btn =$IE.Document.getElementsByTagName("input") | Where-Object{$_.type -eq 'button' -and $_.value -eq '一 覧'}
$btn.Click()

I even used -Match and -Like. Nothing seemed to be working. Please help.

here is the sample, most of the time this error displays enter image description here

1 Answers1

0

The getElementsByTagName shoud definitely work. The reason that the result is $null may be the where closure. Try to get all elements without filtering by value property:

$buttons = $IE.Document.getElementsByTagName("input") | where-object {$_.Type -match "button"}

And do you have encoding set in your page? To handle value in Chinese try this in your page header:

<head><meta charset="utf-8"></head>

Also, a useful post for those, who using frames: Accessing the document object of a frame with JavaScript

Mikhail Tumashenko
  • 1,683
  • 2
  • 21
  • 28
  • The page has charset="utf-8". I tried your suggestion but its still not working. Is there any necessary extension I should install or something? I am a beginner in powershell. I only installed Powershell extension. – Pinky Pal-lingayan Jul 12 '17 at 07:19
  • You mean that $buttons is still $null? For me it's working with stock browser and PS session. But without correct charset the $value I get is incorrect. – Mikhail Tumashenko Jul 12 '17 at 07:35
  • yeah I already tried this codes btn = $IE.Document.getElementsByTagName("input") | Where-Object {$_.class -match 'btn_schedule_search' -and $_.type -match 'button'} $btn.Click() btn = $IE.Document.getElementsByTagName("input") | Where-Object {$_.class -match 'btn_schedule_search' -and $_.type -match 'button' -and $_.value -match '一 覧'} $btn.Click() – Pinky Pal-lingayan Jul 12 '17 at 07:48
  • I used getElementsByTagName and used class, type or even value in where-object. the only thing left is the onclick property – Pinky Pal-lingayan Jul 12 '17 at 07:53
  • I read in a forum, "button is inside an iframe. Iframes dont extrapolate their elements into the parent document object. You would need first get the frame's document and then search on the frame's document for the element to click it.". Can this be a possible cause? I don't have any knowledge about the iframe. – Pinky Pal-lingayan Jul 12 '17 at 08:06
  • Yes. If your page contains an IFrame, then elements inside it will not be available for $IE.Document.getElementsByTagName. But it's not clear from your example if you're using IFrame's in your page. – Mikhail Tumashenko Jul 12 '17 at 08:47
  • and is used. is this it? – Pinky Pal-lingayan Jul 13 '17 at 00:48
  • Yes, the frame is the reason it didn't work. Added a link in my answer, which might be helpful. – Mikhail Tumashenko Jul 25 '17 at 05:46