1

I'm trying to set the disabled attribute of an input element to false with chromedp. I can modify it's value with the console chrome dev tool but didn't achieved it in my code.

I will explain the complete behaviour of this input and why I need it.

  1. I have a first select input that I modify with this command

    err = chromedp.Run(ctx, chromedp.SetValue("select[name=lstDoc]",
        rcp, chromedp.ByQuery))
    if err != nil {
        log.Fatal(err)
    }
    

    Normally you must click it and it automatically change the disabled attributes of the one I'm targeting when you modify it's value. It's working.

  2. Now we arrive at element I can't modify, I can put date in it, so I now my selector is correct put I can't change the disabled attribute, here what I'm actually trying:

    dateDebut := "#txtDebutMAJ"
    err = chromedp.Run(ctx, chromedp.SetAttributeValue(dateDebut,
        "disabled", "false", chromedp.ByQuery))
    if err != nil {
        log.Fatal(err)
    }
    

I have run chromedp with headless at false so i can clearly see that the element is still disabled because it's always grayed out.

What I have tried with the console and it worked:

$("#txtDebutMAJ").disabled = false
kostix
  • 51,517
  • 14
  • 93
  • 176
Romain P
  • 55
  • 1
  • 1
  • 11
  • I have zero experience with chromedp, but judging form the docs, shouldn't it be something like `chromedp.SetAttributeValue("select[name=lstDoc]#txtDebutMAJ", ...)`? That is, the selector expession should match both the node (the element) _and_ the attribute on it. – kostix Feb 25 '21 at 15:11
  • maybe it's not clear in my question but `select[name=lstDoc]` and `#txtDebutMAJ` are two different element, the first one is a select and the second one is an input where you can put some text – Romain P Feb 25 '21 at 15:21

1 Answers1

0

Finally I was able to find a solution and use less code, the origin of the problem is the following, the click on a select don't trigger is onchange attribute so i used the SendKeys function instead.

There is a post about this issue here : https://github.com/chromedp/chromedp/issues/607

and the solution I have used is here : https://github.com/chromedp/chromedp/issues/8#issuecomment-602279477

For conclusion i was using this code to set the value of the select :

    err = chromedp.Run(ctx, chromedp.SetValue("select[name=lstDoc]", rcp, chromedp.ByQuery))
            if err != nil {
                log.Fatal(err)
            }

and this for setting the value of the attribute :

err = chromedp.Run(ctx, chromedp.SetAttributeValue(dateDebut, "disabled", "false", chromedp.ByQuery))
    if err != nil {
        log.Fatal(err)
    }

For finnally only using this piece of code :

err = chromedp.Run(ctx, chromedp.SendKeys(selectRCP, "RCP"))
    if err != nil {
        log.Fatal(err)
    }

work like a charm !

Romain P
  • 55
  • 1
  • 1
  • 11