1

I have tried

driver.find_element_by_xpath( "//div[@class='pepDayScroller_dayNum']").click()

for below elements but it did not work. Please help.

Try to located second element with a number of 2

<div class="pepDayScroller_dayNum">1</div>
<div class="pepDayScroller_dayNum">2</div>
<div class="pepDayScroller_dayNum">3</div>

here is addition information

<div class="pepDayScroller_dayWrapper">
  <a href="#" class="pepDayScroller_day pepDayScroller_day--selected" data-index="0">
    <div class="accessibleText accessibleSelectedMark" aria-hidden="false">Selected</div>
    <div class="pepDayScroller_dayNum">1</div>
    <div class="pepDayScroller_startingFrom"><div 
      class="pepDayScroller_startingFromLabel">Prices vary by date.</div>
    </div>
   </a>
  </div>
<div class="pepDayScroller_dayWrapper"><a href="#" class="pepDayScroller_day pepDayScroller_day--selected" data-index="0"><div class="accessibleText accessibleSelectedMark" aria-hidden="false">Selected</div><div class="pepDayScroller_dayNum">1</div><div class="pepDayScroller_startingFrom"><div class="pepDayScroller_startingFromLabel">Prices vary by date.</div></div></a></div>

once I am able to click on this button, it will scroll down and ask me to select either it is peak or value. codes are below

<a href="#" class="pepTieredCalendar_dateBox tappable pepTieredCalendar_dateBox--32 pepTieredCalendar_dateBox--value" tabindex="0" role="button" data-tier="value" data-date="2018-09-27" aria-label="2018-09-27, 87.30 USD">
                    <span class="pepTieredCalendar_dateBoxText">27</span>
                </a>

how do I find these elements.thanks

1 Answer 1

2

The class which you're trying to refer matches many elements at once. You could try to find by matching text like:

driver.find_element_by_xpath("//*[contains(text(), '2')]")

or by matching all elements and selecting the one that you need:

all_elements = driver.find_elements_by_class_name("pepDayScroller_dayNum")
two_element = None

for el in all_elements:
    if el.text == "2":
        two_element = el
        break

Let me know if that helps.

Sign up to request clarification or add additional context in comments.

6 Comments

It seems work. however, it turns out more problem. it is unable to use .click(). error pop up like this: AttributeError: 'list' object has no attribute 'click'; sorry, i should have post the full code. i will re-post it.
You should post the code you have developed so far, not only the html you're trying to interact with.
the code i have so far is just use to open the websites. that actually is the first step
I edited the first suggestion I've given in my answer to you as it should have been find_element_by_xpath and not find_elements_by_xpath . That's probably the reason why you are getting the error if you're really using it.
the error pop up is because i added .click(). i need to click on it and then it will scroll down and give me another option to select. driver.find_element_by_xpath("//*[contains(text(), '1')]").click()
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.