1

enter image description here

I want to select the text "Auto-Publish" in Span. How can I do it with a CSS selector? with Xpath I know how to do it. I am using Nightwatch for UI automation. I want to make a generic function in the page object which will take a value as a parameter.

SelectFilterValue(value){

   .click(`//span[text()="${value}"]`)  
 }

I can't do it like this since it's an XPath and I have to specify that it's an XPath. If it was a CSS selector I could do it since I don't have to specify that it's a CSS selector. Or is there is any way that I can do it with Xpath too?

cruisepandey
  • 28,520
  • 6
  • 20
  • 38
Dhruv Bhatnagar
  • 121
  • 5
  • 17

2 Answers2

1

CSS does not have any method like text. So in HTMLDOM, it is not possible at this point of time to locate the element based on text.

Moving further, You could do below in nightwatch.js

.useXpath().click('//span[contains(text(), "' + desiredText+ '")]')

and before calling this assign Auto-Publish to the desiredText variable.

cruisepandey
  • 28,520
  • 6
  • 20
  • 38
0

Give a specific id to span tag and then edit css. You can also use inline css which will be the best option.

 <span style="color:blue;"> 
ouflak
  • 2,458
  • 10
  • 44
  • 49
  • I can't do it, it's developed like this throughout the application. I am a tester so have to work with this only. Any other option you could suggest? – Dhruv Bhatnagar Nov 21 '21 at 07:00