Reputation: 65
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.
Upvotes: 2
Views: 67
Reputation: 407
You can use class attribute to locate element:
driver.find_element_by_class_name('koeff')
driver.find_element_by_class_name('bet_type')
Upvotes: 1