2017-10-24 6 views
1

CSSからXPATHに書き直そうとしています。 CSSは以下のように短縮されています:複数のクラスと要素をスキップしてCSSをXPATHに書き換えることができません

div:nth-child(1) > .lay-selection-button span.bet-button-price 

私は相当するxpathを書こうとしています。

//div[1]/button[starts-with(@class=’lay-selection-button span.bet-button-price’)]//span[@class=’bet-button-price’] 

なぜ機能していないのでしょうか。

それは、このsiteからであるか、イメージがhere

でフルCSSは次のとおりです。

div:nth-child(1) > button.bf-bet-button.lay-button.lay-selection-button > div > span.bet-button-price 

そして最後に、私が一番上に持っているもの:

に短縮

#main-wrapper > div > div.scrollable-panes-height-taker > div > div.page-content.nested-scrollable-pane-parent > div > div > div > div.content-page-center-column.coupon-center-column > div > div:nth-child(1) > main > ng-include:nth-child(3) > section.coupon-card.coupon-card-first > div.card-content > bf-coupon-table > div > table > tbody > tr:nth-child(1) > td.coupon-runners > div:nth-child(1) > button.bf-bet-button.lay-button.lay-selection-button > div > span.bet-button-price 

div:nth-child(1) > .lay-selection-button span.bet-button-price 
+1

次のCSS使用するときには、取得しますどのように多くのボタン:button.lay選択ボタンspan.betボタンを-価格? –

+0

@ TonyBui 3列。私はあなたが1つの列のためにできるだけ多くのCSSを短縮したと信じています。私はそれをxpathにする方法が分かりません – Tetora

+1

あなたのxpathは正しくないようです:これを試すことができますか:// div [1]/button [starts-with(@ class = 'lay-selection-button')] // span [@ class = 'bet-button-price'] –

答えて

3

あなたはコードの下での最初の青の列からすべてのprice値を得ることができます:あなたはsize値の代わりに、priceを取得したい場合は

for cell in driver.find_elements_by_xpath('//div[1]/button[@price][2]'): 
    print(cell.get_attribute('price')) 

- ちょうど置き換える:最初のピンクの列については

for cell in driver.find_elements_by_xpath('//div[1]/button[@price][1]'): 
    print(cell.get_attribute('price')) 

cell.get_attribute('price')cell.get_attribute('size')

//div[2]を使用すると、2番目の青/ピンクの列の値を取得することができます//div[3]は、追加のコードを記述するのではなく、第三1つの

+1

おかげでトリックは – Tetora

1
ここ

でのXPathの値を取得します

//tr//*[contains(@class,'coupon-runner')][1]/button[2]//span[contains(@class,'bet-button-price')] 
+0

乾杯しました。また、 – Tetora

+1

を書く便利な方法は、文書の構造を定義し、それに論理的に従います)メソッドとパスのパラメータを 'tr、button and coupon-runner position'にラップすることもできます。表のセル –

関連する問題