1

How to identify the link, I have inspected the elements which are as below :

<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>

I want to identify the class WaidDw or href and click it using python.

Saurabh Gaur
  • 23,507
  • 10
  • 54
  • 73
  • 1
    Your question seems incomplete. Did you forget to add something or accidentally removed something? – koceeng Feb 17 '17 at 07:59

2 Answers2

2

You can try

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

or

driver.find_element_by_xpath('//a[@href="https://mail.google.com" and @aria-label="Mail"]').click()
Naveen Kumar R B
  • 6,248
  • 5
  • 32
  • 65
Andersson
  • 51,635
  • 17
  • 77
  • 129
0

In your provided HTML all attribute's values are unique, you can locate easily that element by using their attribute value.

As your question points to locate this <a class="WaidDw" href="https://mail.google.com" aria-label="Mail" data-track-as="Welcome Header Mail"></a> element. I'm providing you multiple cssSelectors which can work easily to identify the same element as below :-

  • 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']

Note :- Keep in practice (priority) to use cssSelector instead xpath if possible, because cssSelectors perform far better than xpath


Locating Element by CSS Selectors using python :-

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

Clicks the element :-

element.click()

Reference link :-

Community
  • 1
  • 1
Saurabh Gaur
  • 23,507
  • 10
  • 54
  • 73