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)
log.Println(p.page.MustInfo().URL)
isOn, _, err := p.page.Has(`[id="basicRadioButton"]`)
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"]`)
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)
}
if len(wifiRadios) != 2 {
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())
offChecked := offWifiRadio.MustProperty("checked")
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 {
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")
time.Sleep(time.Millisecond * 500)
time.Sleep(time.Millisecond * 100)
saveButton, err := p.page.Element(`input[id="` + p.saveID + `"]`)
if err != nil {
@ -124,6 +99,6 @@ func (p Nucom) SwitchWIFI() error {
}
saveButton.MustClick()
log.Println(p.saveID, "DONE")
time.Sleep(time.Millisecond * 150)
return nil
}