1

I just jump into python programming. I couldn't solve this I tried to several ways

This is target site

<div class="base-components__BaseElement-sc-150tvch-0 sc-VigVT bJRDeW">
<ul role="tablist" class="tabs-header-container">
  <li role="presentation" class="tabheader slot-selector--week-tabheader slot-selector--3-week-tab-space">
    <a href="/groceries/en-GB/slots/delivery/2020-04-09?slotGroup=1" aria-selected="false" class="slot-selector--week-tabheader-link" role="tab" title="Between April 9th - 15th">Apr 09 - 15</a>
  </li>
  <li role="presentation" class="tabheader slot-selector--week-tabheader slot-selector--3-week-tab-space">
    <a href="/groceries/en-GB/slots/delivery/2020-04-16?slotGroup=1" aria-selected="false" class="slot-selector--week-tabheader-link" role="tab" title="Between April 16th - 22nd">Apr 16 - 22</a>
  </li>
  <li role="presentation" class="tabheader active slot-selector--week-tabheader slot-selector--3-week-tab-space">
    <a href="/groceries/en-GB/slots/delivery/2020-04-23?slotGroup=1" aria-selected="true" class="slot-selector--week-tabheader-link" role="tab" title="Between April 23rd - 29th">Apr 23 - 29</a>
  </li>
</ul></div>

and this is my python code

driver.find_element_by_css_selector('.slot-selector--week-tabheader-link').[2].click()
0

You are using find_element instead of find_elementS, find_element only finds the first one.

I like to find elements within elements, this finds the active LI and clicks on it.

list = driver.find_element_by_css_selector('.tabs-header-container')
item = list.find_element_by_css_selector('.active')
item.click()

You can also find multiple elements and take the third one:

links = driver.find_elements_by_css_selector('.slot-selector--week-tabheader-link')
links[2].click()
| improve this answer | |
  • 1
    Great code. solve all of issue Thank you for help – david Apr 9 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.