Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
280 views
in Technique[技术] by (71.8m points)

Can't select drop down button using Selenium Python

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>
question from:https://stackoverflow.com/questions/65837617/cant-select-drop-down-button-using-selenium-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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"]')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...