2017-02-17 9 views
1

HTTPリンクのためにpythonでwebdriverをを使用して要素を識別するために、私は以下のような要素を検査している:どのようにリンクを識別するためにどのように

<div class="vmKOT" role="navigation"> 
<a class="Ml68il" href="https://www.google.com" aria-label="Search" data-track-as="Welcome Header Search"></a> 
<a class="WaidDw" href="https://mail.google.com" aria-label="Mail" data-track-as="Welcome Header Mail"></a> 
<a class="a4KP9d" href="https://maps.google.com" aria-label="Maps" data-track-as="Welcome Header Maps"></a> 
<a class="QJOPee" href="https://www.youtube.com" aria-label="YouTube" data-track-as="Welcome Header YouTube"></a> 
</div> 

私はクラスWaidDwhrefを特定したいとclickそれpythonを使用してください。

+1

あなたの質問は不完全なようです。何かを追加したり、誤って何かを削除したことを忘れましたか? – koceeng

答えて

2

あなたは、すべての属性の値が一意である、あなたはそれらの属性値を使用して簡単にその要素を見つけることができます提供されたHTMLで

driver.find_element_by_class_name('WaidDw').click() 

または

driver.find_element_by_xpath('//a[@href="https://mail.google.com" and @aria-label="Mail"]').click() 
0

を試すことができます。

これは、<a class="WaidDw" href="https://mail.google.com" aria-label="Mail" data-track-as="Welcome Header Mail"></a>の要素を見つけるための質問です。

  • a.WaidDw
  • a.WaidDw[href='https://mail.google.com']
  • a.WaidDw[aria-label='Mail']
  • a.WaidDw[data-track-as='Welcome Header Mail']
  • a.WaidDw[href='https://mail.google.com'][aria-label='Mail']
  • a.WaidDw[href='https://mail.google.com'][aria-label='Mail'][data-track-as='Welcome Header Mail']
- :私はあなたに以下のように同じ要素を識別するために、簡単に作業することができ、複数の cssSelectorsを提供しています

注: - :

element = driver.find_element_by_css_selector('use any one of the given above css selector') 

Clicks the element :-

から
が可能な場合 cssSelectors perform far better than xpath


Locating Element by CSS Selectors using pythonので、代わりにxpathcssSelectorを使用するために、実際に(優先順位)をキープ


参考リンク: -

関連する問題