1

I want to click on the button with special text.

The button looks like

    <button>
    <span class="totalStake">0.00</span> <span class="isocode">USD</span> 
    <span class="freeStake"></span>&nbsp;Place Bet
    </button>

I'm working with python and selenium

from selenium import webdriver
driver = webdriver.Firefox()
driver.get("***")
...

button_text = "Place Bet"       
xpath_wrong = '//button[contains(text(), "%s")]' % button_text  #!!!not working

xpath_good = "//button[text()[contains(.,'%s')]]" % button_text #!!!working

xpath_wrong does not find the element. But xpath_good is successful. I was deadly sure that they do the same things, and that's why I even did not try xpath_good for more than 2 hours trying to find another way of solving the problem.

What is the difference between these expressions?

Charles Duffy
  • 235,655
  • 34
  • 305
  • 356
SKulibin
  • 615
  • 1
  • 5
  • 12

0 Answers0