Kyocera Alerts
Kyocera Alerts

Reputation: 125

Python Selenium Click button by

I'm trying to click the button below but i'm getting a unable to find error.

<div class="sportsbook-outcome-cell__body selected" aria-label="Thomas Almeida " data-tracking="{&quot;section&quot;:&quot;GamesComponent&quot;,&quot;action&quot;:&quot;click&quot;,&quot;target&quot;:&quot;AddBet&quot;,&quot;sportName&quot;:34,&quot;leagueName&quot;:2162,&quot;subcategoryId&quot;:3,&quot;eventId&quot;:179567875}">
   <div class="sportsbook-outcome-body-wrapper">
      <div class="sportsbook-outcome-cell__label-line-container"><span class="sportsbook-outcome-cell__label">Thomas Almeida</span></div>
      <div class="sportsbook-outcome-cell__elements">
         <div class="sportsbook-outcome-cell__element"></div>
         <div class="sportsbook-outcome-cell__element"><span class="sportsbook-odds american default-color">-125</span></div>
      </div>
   </div>
</div>

I've tried by css select which is preferred because there are other names that I have to click on

browser.find_element_by_css_selector("div[aria-label='Thomas Almeida']").click()

I've also tried by full xpath, which only highlights the button it doesnt actually click it

 browser.find_element_by_xpath('/html/body/div[2]/div[2]/section/section[2]/section/div[3]/div/div[3]/div/div/div[2]/div/div[2]/div[2]/div[2]/div/div[1]/div/div').click()

Any help is greatly appreciated.

Thanks,

Upvotes: 0

Views: 67

Answers (2)

Zvjezdan Veselinovic
Zvjezdan Veselinovic

Reputation: 547

I have a preference for using xpath. This is what I use at my current job and I feel like it's a good tool when you want to interact with a web element.

Solution: Find the element by xpath using Thomas's Name and the Game Component "AddBet"

browser.find_element(By.XPATH, "//div[contains(@aria-label, 'Thomas Almeida') and contains(@data-tracking, 'AddBet')]").click()

Upvotes: 0

wasif
wasif

Reputation: 15498

There is a space between the ending quote and "Almeida":

browser.find_element_by_css_selector("div[aria-label='Thomas Almeida ']").click()

Upvotes: 1

Related Questions