1
<div class="row" >
<button type="submit" class="cl-button cl-button--no cl-column">No</button>
<div class="row" >
<button type="submit" class="cl-button cl-column">Yes</button>

I am trying to click a button by fetching text. As they have same class I find no other option. Any ideas? I have tried:

$('div:contains("No")').click()
$(':No').click()
$(':contains("No")').click()
$('button:contains("No")')

but nothing worked for me.

  • Have you tried text() == "No"? – Kate Paulk Mar 29 '18 at 11:40
  • I couldnt succeed with text(). I may have been making a typo but I am not sure what is wrong – Waqas Tahir Mar 29 '18 at 11:54
  • The xpath would be //button[text()='No'] – Bill Hileman Mar 29 '18 at 13:52
  • @BillHileman - thanks - I'm not an xpath expert - I went psuedo-code-ish instead. – Kate Paulk Mar 29 '18 at 14:13
  • Assuming it solved your problem I will add it as an answer instead of a comment so that it can be marked as a solution. Glad to help. – Bill Hileman Mar 29 '18 at 14:21
1

You can use the following xpath to locate the "No" button:

//button[text()='No']
|improve this answer|||||
1

To identify the element using the text

//button[contains(text(),'Yes')]

//button[contains(text(),'No')]

Use these XPath to access the elements.

|improve this answer|||||
0

"No" button has an extra class, you could try css with:

button.cl-button--no
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.