fix nucom switcher, now it is working fine

This commit is contained in:
Urko 2023-06-03 01:08:16 +02:00
parent 5d5d90d3f6
commit 8032850b0b
1 changed files with 12 additions and 37 deletions

View File

@ -72,51 +72,26 @@ func (p Nucom) SwitchWIFI() error {
time.Sleep(time.Millisecond * 500) time.Sleep(time.Millisecond * 500)
log.Println(p.page.MustInfo().URL) log.Println(p.page.MustInfo().URL)
isOn, _, err := p.page.Has(`[id="basicRadioButton"]`) offWifiRadio, err := p.page.Element(`input[type="radio"][name="radiohiddenButton"][value="0"]`)
if err != nil {
return fmt.Errorf("page.Element %s: %s", p.wifiRadioID, err)
}
log.Println("is on", isOn)
if !isOn {
warningButton, err := p.page.Element(`[value="` + p.configureWarningID + `"]`)
if err != nil {
return fmt.Errorf("page.Element %s: %s", p.configureWarningID, err)
}
warningButton.MustClick()
log.Println(warningButton, "DONE")
}
wifiRadios, err := p.page.Elements(`[name="radiohiddenButton"]`)
if err != nil { if err != nil {
return fmt.Errorf("page.Element %s: %s", p.wifiRadioID, err) return fmt.Errorf("page.Element %s: %s", p.wifiRadioID, err)
} }
if len(wifiRadios) != 2 { offChecked := offWifiRadio.MustProperty("checked")
return fmt.Errorf("radios not found")
}
offChecked := wifiRadios[0].MustProperty("checked")
log.Println("wifiRadios[0]", wifiRadios[0].MustProperty("checked"))
log.Println("wifiRadios[1]", wifiRadios[1].MustProperty("checked"))
log.Println("offChecked.Bool()", offChecked.Bool())
if offChecked.Bool() { if offChecked.Bool() {
wifiRadios[1].MustClick() log.Println("it is off, let's switch on")
onRadio, err := p.page.Element(`input[type="radio"][name="radiohiddenButton"][value="1"]`)
if err != nil {
return fmt.Errorf("page.Element %s: %s", p.wifiRadioID, err)
}
onRadio.MustClick()
} else { } else {
wifiRadios[0].MustClick() log.Println("it is on, time to switch off")
offWifiRadio.MustClick()
} }
wifiRadios, err = p.page.Elements(`[name="radiohiddenButton"]`)
if err != nil {
return fmt.Errorf("page.Element %s: %s", p.wifiRadioID, err)
}
offChecked, err = wifiRadios[0].Property("checked")
if err != nil {
return fmt.Errorf("page.Element %s: %s", p.wifiRadioID, err)
}
log.Println("offChecked.Bool() AFTER CHECK", offChecked.Bool())
log.Println(p.wifiRadioID, "DONE") log.Println(p.wifiRadioID, "DONE")
time.Sleep(time.Millisecond * 100)
time.Sleep(time.Millisecond * 500)
saveButton, err := p.page.Element(`input[id="` + p.saveID + `"]`) saveButton, err := p.page.Element(`input[id="` + p.saveID + `"]`)
if err != nil { if err != nil {
@ -124,6 +99,6 @@ func (p Nucom) SwitchWIFI() error {
} }
saveButton.MustClick() saveButton.MustClick()
log.Println(p.saveID, "DONE") log.Println(p.saveID, "DONE")
time.Sleep(time.Millisecond * 150)
return nil return nil
} }