1

This Java Version of this question is both aptly asked, and answered, at Java Version.

However, the question, and therefore the excellent accepted answer, was specific to Java.

How can this be done with Python? hence asking this question and providing details of my specific case below.

I am trying to click the select all checkbox element (well, inside the checkbox really) as shown in the below picture:

enter image description here

The actual clickable area is sitting inside the checkbox element, represented by the ::before pseudo element in the DOM shown in picture above.

Noting that the pseudo elements cannot be referenced using XPATH, I want to access this ::before pseudo element by physically using the mouse click, referencing the ::before element by pointing the mouse to the center of the checkbox at the below XPATH, using Selenium Python:

//span[text()="Transmission (TX) to eNodeB"]/ancestor::h2/following-sibling::div/descendant::label[1]

The XPATH is working to locate the top left of the checkbox element, validated by the 1 result yellow highlighted using chrome's find element in picture.

TendaiM
  • 163
  • 1
  • 1
  • 9
  • Show us your code efforts until now (a minimal reproducible example), and also confirm the url, if it's public facing. – Barry the Platipus Aug 12 '22 at 08:24
  • Isn't the `label` -> `span` text enough to identify the element? – undetected Selenium Aug 12 '22 at 08:40
  • Unfortunately the url is not public facing. I have not yet written code to achieve the desired result, need to find out how the solution at the referenced Q&A can be adopted to Python, or any other ways to achieve same result. I will share any attempts I will write here. – TendaiM Aug 12 '22 at 08:40
  • @undetectedSelenium no, the //span[@text()='Select all rows'] identifies the //span element, but not the ::before or ::after pseudo elements. However, I have other motivation to use that structure to identify the element, I want to change the "Transmission (TX) to eNodeB" string using a variable to click checkboxes elsewhere in the website DOM. – TendaiM Aug 12 '22 at 08:43
  • @undetectedSelenium no, the //span[@text()='Select all rows'] identifies the //span element, but not the ::before or ::after pseudo elements. However, I have other motivation to use that structure to identify the element, I want to change the "Transmission (TX) to eNodeB" string using a variable to click OTHER "Select all rows" checkboxes elsewhere in the website DOM. – TendaiM Aug 12 '22 at 08:49
  • To change the "Transmission (TX) to eNodeB" string, you don't need to deal with _`::before`_ or _`::after`_, See: [How locate the pseudo-element ::before using Selenium Python](https://stackoverflow.com/a/59706267/7429447) – undetected Selenium Aug 12 '22 at 10:16

1 Answers1

0

There is no way you can select or click CSS pseudo-element since even if you see it in HTML DOM-tree it's not present in DOM!

You need to select checkbox input field. Try XPath

//input[@type='checkbox']

or more specific

//div[.//span='Transmission (TX) to eNodeB']//input[@type='checkbox']

P.S. To get better solution you need to provide HTML as text for ancestors as well

DonnyFlaw
  • 581
  • 3
  • 9