admin管理员组

文章数量:1292955

I am automating an web application and I need to type in a value in an input text box.

My plan is to develop an friendly function, where in if I pass the label associated with the text , I should be able to enter the value. In this scenario, I am not dependant on xpaths or anything else, only the label. I figured out the selector. It is

selector = `::-p-aria(${textboxLabel}) ::-p-aria([role="textbox"])`;

but the issue is the text box label. We dont know the exact label text but only a partial label text. What I mean by here is , it can be like any of the below

Is it possible to get a selector which satisfies a partial label text, in this case, "First"

Its an augular application and WCAG2.0 compatible. But -p-aria only supports exact label text

Tried,

 selector = `::-p-text(${textboxLabel})`;
but it is pointing to the label element and not to the input element.

Any help is appreciated. I am after a selector which gets the partial text as input and any other input ( which is generic ) to identify the text box, I mean point to the input tag. Thank you

I am automating an web application and I need to type in a value in an input text box.

My plan is to develop an friendly function, where in if I pass the label associated with the text , I should be able to enter the value. In this scenario, I am not dependant on xpaths or anything else, only the label. I figured out the selector. It is

selector = `::-p-aria(${textboxLabel}) ::-p-aria([role="textbox"])`;

but the issue is the text box label. We dont know the exact label text but only a partial label text. What I mean by here is , it can be like any of the below

Is it possible to get a selector which satisfies a partial label text, in this case, "First"

Its an augular application and WCAG2.0 compatible. But -p-aria only supports exact label text

Tried,

 selector = `::-p-text(${textboxLabel})`;
but it is pointing to the label element and not to the input element.

Any help is appreciated. I am after a selector which gets the partial text as input and any other input ( which is generic ) to identify the text box, I mean point to the input tag. Thank you

Share Improve this question asked Feb 13 at 4:51 Timothy RajanTimothy Rajan 1,9579 gold badges44 silver badges65 bronze badges 3
  • If you can find the label, the input is probably a sibling so just add ~ input. Maybe I misunderstood that – pguardiario Commented Feb 14 at 3:29
  • ::-p-text(First) uses a substring, and if you click the label it should focus the input. Can you share some sample HTML? – ggorlen Commented Feb 14 at 6:17
  • I think there are partial selectors you can use: Ends With ($=), Begins with (^=) , and Contains (*=). – first last Commented Feb 18 at 8:55
Add a comment  | 

1 Answer 1

Reset to default 0

Thanks everyone for responding to my question. Unfortunately, Puppeteer does not have a direct answer to this scenario. The only way to achieve the outcome is to filter out all text boxes and then apply another filter to find the right text box. Not an direct fix but an hack based on the label element.

I mean, formulate an XPath to find an label element which has "First" and then from that collection, apply an index.

Happy to help if you need more information

STEP 1 : Find all text boxes. =>collection1[]

STEP 2 : Find those text boxes who has First as an associated Label=>collection2[]

STEP 3 : Fetch as per the index, Say collection2[0]

本文标签: cssPuppeteerUnable to select an input box based on paria and ptextStack Overflow