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: </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"> for </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>
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
select.select_by_visible_text("All Transactions")
select.select_by_value("All Transactions")
select.select_by_index(1)
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.
Related
I have a Visualforce page form to create Leads in Salesforce
In the form I want to add the State Picklist.
On the Lead object Address is a composite field. As per documentation, the State field is as seen here -
Field Name
Field Label
Type
Length
State
State/Province
String
80
I want the State on the visualforce page to look like this. i.e when I click on Select a State , I should see the list of State that i can choose from.
This is the CSS code I tried
<label for="state">State</label>
<select name="state" id="state">
<option value="" selected="selected">Select a State</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select> <br>
Can someone please guide, how I could translate this to VFP to use the following tag
<apex:selectOptions value="{!State}" /
No no, the value user selected ({!Lead.State}) should be bound to parent tag, not to <apex:selectOptions>. SelectOptions is just list of choices. And then you render them as a picklist (normal or multiselect), list of checkboxes, list of radio buttons... How you use them is separate from how they're defined, which values (if any are disabled...)
If you want to keep it in pure Visualforce - look into <apex:selectOption>, you could run some search-replace on your code and you're almost there. If you want to generate the list in Apex (if you need it for something else, maybe validations? Maybe you'd want to store it in config object or custom metadata and then admin can tweak the lists without code changes?) - <apex:selectOptions> and you pass to it a List<SelectOption>.
If your implementation is only US-specific then maybe you should look into config solution rather than code. https://help.salesforce.com/articleView?id=sf.admin_state_country_picklists_configure.htm&type=5
i have an form with some text fields and dropdowns.
I am using bootstrap which users jQuery.
The problem is the required="required" attribute in the ASP dropdown control is not working.
Is working on text fields, but not no in dropdown.
here dont work:
<asp:DropDownList ID="orderTypesDropDownList" runat="server" CssClass="form-control" required="required" DataSourceID="purchaseOrderTypesDS" DataTextField="PurchaseOrderType" DataValueField="TypeID" AppendDataBoundItems="True">
<asp:ListItem Selected="True">-- SELECT --</asp:ListItem>
</asp:DropDownList>
But here works:
How can i make it works in the ASP dropdown like in the ASP textBox?
I was checking the DOM of the page after compile and looks like this:
<select name="ctl00$ContentPlaceHolder1$userBudget$orderTypesDropDownList" id="ctl00_ContentPlaceHolder1_userBudget_orderTypesDropDownList" class="form-control" required="required">
<option selected="selected" value="-- SELECT --">-- SELECT --</option>
<option value="8">AmEx PCard</option>
<option value="14">E-Victor Purchase</option>
<option value="13">In-House Job</option>
<option value="3">Internal Unit Request</option>
<option value="2">Invoice</option>
<option value="4">Journal Entry</option>
<option value="16">Material Move Request</option>
<option value="11">Material Request Tag</option>
<option value="12">Rapid Purchase</option>
<option value="17">Smart Buy Blanket PO</option>
<option value="6">Smart Buy PO</option>
<option value="15">Spare PO</option>
So its should be working, why is not working?
I am using ASP 4.0 framework with web forms.
The first value should be empty when using "required" in a select. (value="")
I'm trying to do something like this on the dropdown
I already tried different tag but failed to see the expected
<option id="makeDefault" value="0">Make <label class="option-placeholder">e.g. BMW, Mercedes</label></option>
Try this:
<select>
<option value="" disabled selected hidden>MAKE e.g. BMW...</option>
<option value="0">list item 1</option>
<option value="1">list item 2</option>
</select>
FIDDLE: https://jsfiddle.net/L0k6x0dh/1/
If I use the following xPath:
//*[contains(#class, 'some-label') and contains(., 'MT:Week')]
It gets me exactly one element (a <span>) as expected. So far so good.
What I want is to get the <select> right next to it, but by doing this:
//*[contains(#class, 'some-label') and contains(., 'MT:Week')]/following::select
It already selects two <select> elements. How do I select just one without using the name attribute (!) ?
The HTML:
<div>
<label>
<span class="some-label">MT:Month</span>
<select name="month" id="someID">
<option selected="selected" value="12">March 2015</option>
</select>
</label>
</div>
<div>
<label>
<span class="some-label">MT:Week</span>
<!-- want to select just the below one -->
<select class="width-50px" name="monthWeek" id="someOtherID">
<option selected="selected" value="">All</option>
<option value="CalendarWeek{year=2015, week=9}">9</option>
<option value="CalendarWeek{year=2015, week=10}">10</option>
</select>
</label>
</div>
<div>
<label>
<span class="some-label">MT:Type</span>
<select name="type" id="anotherID">
<option selected="selected" value="">All</option>
<option value="someValue">Value 1</option>
<option value="someValue2">Value 2</option>
</select>
</label>
</div>
You could use [1] to get the first:
//*[contains(#class, 'some-label') and contains(., 'MT:Week')]/following::select[1]
But you probably only want the one within the same label, so use following-sibling:
//*[contains(#class, 'some-label') and contains(., 'MT:Week')]/following-sibling::select
I am trying to use capybara to target a value within a dropdown menu that lives within an iframe. Here is the HTML for the dropdown that I am trying to select:
<select class="colored required" aria-required="true" id="birthdate-month" name="birthdate-month" aria-label="Birth Month">
<option value="">Month</option>
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
Here is the step definition I have written to try and target that dropdown menu and select an option within it:
find('#birthdate-month').find(:xpath, 'option[06]').select_option
When I run this, I get:
'Unable to find css "#birthdate-month" (Capybara::ElementNotFound)'.
Any ideas on what I'm doing wrong? Thanks!
EDIT:
I got it to work by inserting this into my step definition
browser = page.driver.browser
browser.switch_to.frame(iframe_name)
step(step)
browser.switch_to.default_content