Reputation: 125
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="{"section":"GamesComponent","action":"click","target":"AddBet","sportName":34,"leagueName":2162,"subcategoryId":3,"eventId":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
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
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