How to handle/get/create the xpath of the objects having pseudo elements ::before or ::after

Hi Team,

Could please help me to handle the cross button of the PopUp Window.
I am not able to get its exact xpath.

I tried with Accept Alert inbuilt keyword, but still not working.

Thanks in advance.

Cross Button.png

Cross Button1.png

1 Like

In custom keywords you can used a TestObject with this xpath //div[@class=‘ngdialog-close’]
And next with this type of click
Actions action = new Actions(driver)
action.click(element).build().perform()

Rosary,

You want to select the

. Then the following XPath expression will work:

//div[@id='ngdialog2']/div[contains(@class,'ngdialog-content')]/div[contains(@class,'ngdialog-close')]

----

By the way, you wrote

the xpath of the objects having pseudo elements ::before or ::after

You are confused. The “pseudo element” is a terminology used in CSS selector. XPath specification does not define ::before and ::after.

In this forum comment, I typed this XPath expression:
//div[@id='ngdialog2']/div[@class='ngdialog-content']/div[@class='ngdialog-close']

This line is wrongly rendered by the Forum application as this:

//div[@id=‘ngdialog2’]/div[@class=‘ngdialog-content’]/div[@class=‘ngdialog-close’]

The Forum application has a bug. It consumes a character sequence class='xxxx- away.

A workaround is to enclose the XPath in a pair of HTML code element: …

<code>//div[@id='ngdialog2']/div[@class='ngdialog-content']/div[@class='ngdialog-close']</code>