I'm new to Python and coding in general. I'm trying to click on a button within a dropdown, but can't figure out how to achieve this.
I'm able to click on the dropdown button 'Sort', but couldn't click on the 'Oldest' option after that. Here's what the source code looks like. Here's the full code in a screenshot.
<button id="review_filter_sort_trigger" aria-controls="review_filter_sort" aria-haspopup="true" aria-expanded="false" aria-label="Sort" class="css-168oqwy eanm77i0" type="button" data-comp="DropdownTrigger StyledComponent BaseComponent "><div class="css-14hpmdh eanm77i0" data-comp="Pill StyledComponent BaseComponent ">Sort<svg aria-hidden="true" viewBox="0 0 95 57" class="css-1366on3 eanm77i0" data-comp="Chevron StyledComponent "><path d="M47.5 57L95 9.5 85.5 0l-38 38-38-38L0 9.5 47.5 57z"></path></svg></div></button> ... <div id="review_filter_sort" aria-labelledby="review_filter_sort_trigger" class="css-82y43r eanm77i0" data-comp="CustomScroll StyledComponent BaseComponent "><button data-at="sort_option" type="button" class="css-1aawth6 eanm77i0" data-comp="RadioFilter StyledComponent BaseComponent ">Most Helpful</button><button data-at="sort_option" type="button" class="css-1aawth6 eanm77i0" data-comp="RadioFilter StyledComponent BaseComponent ">Highest Rating</button><button data-at="sort_option" type="button" class="css-1aawth6 eanm77i0" data-comp="RadioFilter StyledComponent BaseComponent ">Lowest Rating</button><button data-at="sort_option" type="button" class="css-1aawth6 eanm77i0" data-comp="RadioFilter StyledComponent BaseComponent ">Oldest</button><button data-at="sort_option" type="button" class="css-1aawth6 eanm77i0" data-comp="RadioFilter StyledComponent BaseComponent ">Newest</button></div> <button data-at="sort_option" type="button" class="css-1aawth6 eanm77i0" data-comp="RadioFilter StyledComponent BaseComponent ">Most Helpful</button> <button data-at="sort_option" type="button" class="css-1aawth6 eanm77i0" data-comp="RadioFilter StyledComponent BaseComponent ">Highest Rating</button> <button data-at="sort_option" type="button" class="css-1aawth6 eanm77i0" data-comp="RadioFilter StyledComponent BaseComponent ">Lowest Rating</button> <button data-at="sort_option" type="button" class="css-1aawth6 eanm77i0" data-comp="RadioFilter StyledComponent BaseComponent ">Oldest</button> <button data-at="sort_option" type="button" class="css-1aawth6 eanm77i0" data-comp="RadioFilter StyledComponent BaseComponent ">Newest</button>
I can't replicate your errors, because your link is redirecting me to the homepage. You might want to select the button of interest by the text.
driver.find_element_by_xpath('//button[text()="Lowest Rating"]')
2.1m questions
2.1m answers
60 comments
57.0k users