2

I try to locate some text from a java element with python selenium.

<div id="allBetsTable" data-gameid="89519742" style="transition-timing-function: cubic-bezier(0.1, 0.57, 0.1, 1); transition-duration: 0ms; transform: translate(0px, 0px) translateZ(0px);"><div class="bet_group_col cols1"><div><div class="bet_group"><div class="bet-title bet-title_justify"><span class="bet-title__star"></span> 
            Match-Ups, 1X2. Duel between Players (Goals)
         <!----></div> <div class="bets betCols3"><div class=""><span data-type="13087" class="bet_type">Match-Up Leigh Griffiths - Jonathan David - Celtic
        <!----> <!----> <!----></span> <span data-coef="3.755" class="koeff"><i>3.755</i></span></div><div class=""><span data-type="13089" class="bet_type">Match-Up Leigh Griffiths - Jonathan David - X
        <!----> <!----> <!----></span> <span data-coef="1.567" class="koeff"><i>1.567</i></span></div><div class=""><span data-type="13088" class="bet_type">Match-Up Leigh Griffiths - Jonathan David - Lille OSC
        <!----> <!----> <!----></span> <span data-coef="3.976" class="koeff"><i>3.976</i></span></div></div></div></div><div><div class="bet_group"><div class="bet-title bet-title_justify"><span class="bet-title__star"></span> 
            Match-Ups, Double Chance. Duel between Players (Goals)
         <!----></div> <div class="bets betCols3"><div class=""><span data-type="13090" class="bet_type">Match-Up Leigh Griffiths - Jonathan David , Double Chance - CelticX
        <!----> <!----> <!----></span> <span data-coef="1.106" class="koeff"><i>1.106</i></span></div><div class=""><span data-type="13092" class="bet_type">Match-Up Leigh Griffiths - Jonathan David , Double Chance - Celtic Lille OSC
        <!----> <!----> <!----></span> <span data-coef="1.931" class="koeff"><i>1.931</i></span></div><div class=""><span data-type="13091" class="bet_type">Match-Up Leigh Griffiths - Jonathan David , Double Chance - Lille OSCX
        <!----> <!----> <!----></span> <span data-coef="1.124" class="koeff"><i>1.124</i></span></div></div></div></div><div><div class="bet_group"><div class="bet-title bet-title_justify"><span class="bet-title__star"></span> 
            Match-Ups, Total. Duel between Players (Goals)
         <!----></div> <div class="bets betCols2"><div class=""><span data-type="13093" class="bet_type">Match-Up Leigh Griffiths - Jonathan David, Total Goals Over (0.5)
        <!----> <!----> <!----></span> <span data-coef="1.686" class="koeff"><i>1.686</i></span></div><div class=""><span data-type="13094" class="bet_type">Match-Up Leigh Griffiths - Jonathan David, Total Goals Under (0.5)
        <!----> <!----> <!----></span> <span data-coef="1.776" class="koeff"><i>1.776</i></span></div><div class=""><span data-type="13093" class="bet_type">Match-Up Leigh Griffiths - Jonathan David, Total Goals Over (1)
        <!----> <!----> <!----></span> <span data-coef="3.456" class="koeff"><i>3.456</i></span></div><div class=""><span data-type="13094" class="bet_type">Match-Up Leigh Griffiths - Jonathan David, Total Goals Under (1)
        <!----> <!----> <!----></span> <span data-coef="1.154" class="koeff"><i>1.154</i></span></div><div class=""><span data-type="13093" class="bet_type">Match-Up Leigh Griffiths - Jonathan David, Total Goals Over (1.5)
        <!----> <!----> <!----></span> <span data-coef="5.32" class="koeff"><i>5.32</i></span></div><div class=""><span data-type="13094" class="bet_type">Match-Up Leigh Griffiths - Jonathan David, Total Goals Under (1.5)
        <!----> <!----> <!----></span> <span data-coef="1.033" class="koeff"><i>1.033</i></span></div></div></div></div><div><div class="bet_group"><div class="bet-title bet-title_justify"><span class="bet-title__star"></span> 
            Match-Ups, Handicap. Duel between Players (Goals)
         <!----></div> <div class="bets betCols2"><div class=""><span data-type="13095" class="bet_type">Match-Up Leigh Griffiths - Jonathan David, Handicap Celtic (0)
        <!----> <!----> <!----></span> <span data-coef="1.682" class="koeff"><i>1.682</i></span></div><div class=""><span data-type="13096" class="bet_type">Match-Up Leigh Griffiths - Jonathan David, Handicap Lille OSC (0)
        <!----> <!----> <!----></span> <span data-coef="1.781" class="koeff"><i>1.781</i></span></div></div></div></div></div> </div>

I want to locate this line:

<span data-coef="1.686" class="koeff"><i>1.686</i></span></div><div class=""><span data-type="13094" class="bet_type">Match-Up Leigh Griffiths - Jonathan David, Total Goals Under (0.5)

I know how to locate it with xpath and css selector, but it's moving (elements change position sometimes) and that's why the xpath is changing.

6
  • What xpath/css have you tried? Please provide some code. Commented Dec 10, 2020 at 21:49
  • allbets = driver.find_element_by_id("allBetsTable") Commented Dec 10, 2020 at 22:22
  • odds = allbets.find_element_by_css_selector("div > div:nth-child(3) > div > div.bets.betCols2 > div:nth-child(2) > span.koeff").text Commented Dec 10, 2020 at 22:24
  • but sometimes it is div:nth-child(3) instead of div:nth-child(2) Commented Dec 10, 2020 at 22:25
  • so the only fixed value in the line I'm looking for is Total Goals Under (0.5) Commented Dec 10, 2020 at 22:26

1 Answer 1

1

You can use class attribute to locate element:

driver.find_element_by_class_name('koeff')
driver.find_element_by_class_name('bet_type')
Sign up to request clarification or add additional context in comments.

3 Comments

also by xpath: //span[@data-coef='1.686']
1.686 is not fixed
@Phil What data exactly do you want to get based on what text/attribute value?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.