0

I'm using Selenium with Python 3.5 to scrape various websites. However, I need to select from a drop-down list but keep getting an error. I'm quite embarrassed I can't get this to work, but XPath is brand new to me so your help is appreciated. The truncated version of my code is:

driver.implicitly_wait(4)
driver.find_element_by_xpath("//select[@id='ddaShowForm']/
    option[@value='Deposits']/text()").click()

I have the wait there to make sure the page is fully loading because that was something that got me before. The error I'm getting is that it can't find the element. Thanks for your help!

Here is a snippet of the relevant area of the page. I'm sorry for the poor formatting.

<form id="ddaShowForm" action="https://online.wellsfargo.com/das/cgi-bin/session.cgi?sessargs=xUog_f8DdTZHif-5iVUuuwe9XQVqncvm" method="post">
<label for="transactionType">Show: &nbsp;</label>
<select id="transactionType" name="showTabDDACommand.transactionTypeFilterValue">
    <option value="All Transactions" selected="selected">All Transactions</option>
    <option value="All Transactions One Column">All Transactions in One Column</option>
    <option value="All Transactions with Balance">All Transactions with Balances</option>
    <option value="Bill Pay">Bill Pay Transactions</option>
    <option value="Check Card">Debit Card / ATM Card Transactions</option>
    <option value="Checks">Checks</option>
    <option value="Deposits">Deposits</option>
    <option value="Withdrawls">Withdrawals</option>
    <option value="transactionTypeFilter.p2p.label">WF SurePay</option>
    <option value="transactionTypeFilter.wire.label">Wires</option>
</select>
<label for="timeFilter">&nbsp;&nbsp;for&nbsp;</label>
<select id="timeFilter" name="showTabDDACommand.timeFilterValue" size="1">
    <optgroup label="" >
        <option value="3" selected="selected" >Last 90 Days</option>
        <option value="4"  >Last 6 Months</option>
        <option value="5"  >Last 12 Months</option>
        <option value="6"  >Last 18 Months</option>
        <option value="7"  >Since Last Logon</option>
        <option value="8"  >Since Last Statement</option>
        <optgroup label="--------------------" class="optgroupstyle"></optgroup>
        <option value="11"  >Date Range</option>
    </optgroup>
</select>
2
  • can you share relevant HTML Commented Jan 16, 2016 at 13:31
  • I was trying to avoid doing that because it's horribly formatted but I don't know what the correct formatting is either. I will add it with edit. Commented Jan 16, 2016 at 13:34

2 Answers 2

1

For Selecting an element from dropdown you can use Select

from selenium.webdriver.support.ui import Select
select = Select(driver.find_element_by_id("transactionType"))

Then you can select using any of the methods provided by Select

  1. select.select_by_visible_text("All Transactions")
  2. select.select_by_value("All Transactions")
  3. select.select_by_index(1)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much pArAs. I accept this answer with the correction (for anyone who finds this in the future) that I pointed you towards the wrong 'id'. For anyone who looks at the html to reverse engineer this, "ddaShowForm" should instead be "transactionType".
0

Thanks to the help received by pArAs, I would like to answer the original XPath question for anyone who stumbles upon this in the future. His method pointed out to me that the "ddaShowForm" is actually a form and not a 'select' element. The correct syntax for my original XPath is

driver.find_element_by_xpath("//select[@id='transactionType']/
option[@value='Deposits']").click()

If you look at the html, the 'select' element actually has id "transactionType". I would like to point out that I also removed the "/text()" at the end. I hope this helps.

Comments

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.