Я попытался использовать несколько подходов, упомянутых в подобных вопросах, но безуспешно. В исходном коде HTML явно выбран id = "origin". Я попытался использовать решение xpath для случая, когда выборка вызывает другое «происхождение». Я новичок в Selenium, любая помощь будет оценена.
HTML класс:
<code><div class="col-xs-12 col-smv-6 col-lgv-12 wrapper airport origin">
<label for="origin-search" style="outline: 0px;">From:</label>
<div class="container-select">
<input id="origin-value" data-history-key="origin" data-history="true" type="hidden" value="SEA" style="outline: 0px;">
<select id="origin" class="hidden" style="outline: 0px;"><option value=""></option><option value="YOW">Ottawa, ON</option><option value="JAX">Jacksonville, FL</option><option value="MXP">Milan, Italy</option><option value="HNL">Honolulu, Oahu, Hawaii</option><option value="CDG">Paris, France</option><option value="STL">St. Louis, MO</option><option value="XNA">Fayetteville/Springfield, AR</option><option value="DFW">Dallas Fort Worth, TX</option><option value="PNS">Pensacola, FL</option><option value="SDF">Louisville, KY</option><option value="MHT">Manchester, NH</option><option value="LFT">Lafayette, LA</option><option value="CUN">Cancun, Mexico</option><option value="HOG">Holguin, Cuba</option><option value="CUR">Willemstad, Curacao</option><option value="EYW">Key West, FL</option><option value="OMA">Omaha, NE</option><option value="CUU">Chihuahua, Mexico</option><option value="MIA">Miami, FL</option><option value="LGA">New York (LaGuardia), NY</option><option value="MYR">Myrtle Beach, SC</option><option value="MID">Merida, Mexico</option><option value="YQB">Quebec City, QC</option><option value="BCN">Barcelona, Spain</option><option value="IAD">Washington (Dulles), VA</option><option value="YQG">Windsor, ON</option><option value="SEA">Seattle, WA</option><option value="HOU">Houston-Hobby, TX</option><option value="POP">Puerto Plata, Dominican Republic</option><option value="IAH">Houston (G. Bush Intercontinental), TX</option><option value="YQM">Moncton, NB</option><option value="YQL">Lethbridge, AB</option><option value="CVG">Cincinnati, OH</option><option value="POS">Port of Spain, Trinidad and Tobago</option><option value="RSW">Fort Myers, FL</option><option value="YQQ">Comox, BC</option><option value="YQR">Regina, SK</option><option value="YQU">Grande Prairie, AB</option><option value="YQT">Thunder Bay, ON</option><option value="LGW">London (Gatwick), United Kingdom</option><option value="BDA">St. George's, Bermuda</option><option value="YQY">Sydney, NS</option><option value="YQX">Gander, NL</option><option value="BTR">Baton Rouge, LA</option><option value="RTB">Roatan, Honduras</option><option value="ABE">Allentown, PA</option><option value="MZT">Mazatlan, Mexico</option><option value="FLL">Fort Lauderdale, FL</option><option value="HPN">White Plains, NY</option><option value="BDL">Hartford, CT</option><option value="DHN">Dothan, AL</option><option value="GNV">Gainesville, FL</option><option value="VLD">Valdosta, GA</option><option value="QRO">Queretaro, Mexico</option><option value="ABQ">Albuquerque, NM</option><option value="BUF">Buffalo (Niagara), NY</option><option value="ABY">Albany, GA</option><option value="SFO">San Francisco, CA</option><option value="ACA">Acapulco, Mexico</option><option value="RDU">Raleigh Durham, NC</option><option value="MKE">Milwaukee, WI</option><option value="YBR">Brandon, MB</option><option value="ACK">Nantucket, MA</option><option value="LIH">Lihue, Kauai, Hawaii</option><option value="TYS">Knoxville, TN</option><option value="HAJ">Hannover, Germany</option><option value="BES">Brest, France</option><option value="SGF">Springfield, MO</option><option value="LIR">Liberia, Costa Rica</option><option value="ATH">Athens, Greece</option><option value="HAM">Hamburg, Germany</option><option value="LIS">Lisbon, Portugal</option><option value="ATL">Atlanta, GA</option><option value="YCD">Nanaimo, BC</option><option value="ICT">Wichita, KS</option><option value="CHA">Chattanooga, TN</option><option value="MLB">Melbourne, FL</option><option value="SXM">Philipsburg, St. Martin/St. Maarten</option><option value="GPT">Gulfport/Biloxi, MS</option><option value="CHO">Charlottesville, VA</option><option value="MLI">Moline, IL</option><option value="FNT">Flint, MI</option><option value="AUA">Oranjestad, Aruba</option><option value="JFK">New York (JFK), NY</option><option value="CHS">Charleston, SC</option><option value="BWI">Baltimore, MD</option><option value="PBI">West Palm Beach, FL</option><option value="MLU">Monroe, LA</option><option value="YDF">Deer Lake/Corner Brook, NL</option><option value="AUS">Austin, TX</option><option value="SYD">Sydney, NSW</option><option value="SHV">Shreveport, LA</option><option value="PSC">Pasco, WA</option><option value="BGI">Bridgetown, Barbados</option><option value="YDQ">Dawson Creek, BC</option><option value="HSV">Huntsville/Decatur, AL</option><option value="BGR">Bangor, ME</option><option value="PSP">Palm Springs, CA</option><option value="SYR">Syracuse, NY</option><option value="YUL">Montreal, QC</option><option value="KIN">Kingston, Jamaica</option><option value="AEX">Alexandria, LA</option><option value="AVL">Asheville/Hendersonville, NC</option><option value="CZM">Cozumel, Mexico</option><option value="OAJ">Jacksonville, NC</option><option value="YEG">Edmonton, AB</option><option value="AVP">Wilkes-Barre/Scranton, PA</option><option value="ORD">Chicago (O'Hare), IL</option><option value="ORF">Norfolk, VA</option><option value="BHM">Birmingham, AL</option><option value="GRR">Grand Rapids, MI</option><option value="GRU">Sao Paulo, Brazil</option><option value="SJD">San Jose del Cabo, Mexico</option><option value="SJC">San Jose, CA</option><option value="TLH">Tallahassee, FL</option><option value="YVR">Vancouver, BC</option><option value="YFC">Fredericton, NB</option><option value="VPS">Destin-Ft Walton Beach, FL</option><option value="SJO">San Jose, Costa Rica</option><option value="SJU">San Juan, Puerto Rico</option><option value="MOB">Mobile, AL</option><option value="GSO">Greensboro, NC</option><option value="PUJ">Punta Cana, Dominican Republic</option><option value="GSP">Greenville-Spartanburg, SC</option><option value="PDX">Portland, OR</option><option value="YWG">Winnipeg, MB</option><option value="HUX">Huatulco, Mexico</option><option value="BIQ">Biarritz, France</option><option value="BZE">Belize City, Belize</option><option value="AGS">Augusta, GA</option><option value="RIC">Richmond, VA</option><option value="FAI">Fairbanks, AK</option><option value="GCM">George Town, Grand Cayman, Cayman Islands</option><option value="FRA">Frankfurt, Germany</option><option value="BZN">Bozeman, MT</option><option value="ZIH">Ixtapa/Zihuatanejo, Mexico</option><option value="CLE">Cleveland, OH</option><option value="FAY">Fayetteville, NC</option><option value="NAS">Nassau, Bahamas</option><option value="GTR">Columbus, MS</option><option value="VRA">Varadero, Cuba</option><option value="YXC">Cranbrook, BC</option><option value="YXE">Saskatoon, SK</option><option value="YXH">Medicine Hat, AB</option><option value="MPL">Montpellier, France</option><option value="YXJ">Fort St. John, BC</option><option value="CLT">Charlotte (Douglas), NC</option><option value="SLC">Salt Lake City, UT</option><option value="PVR">Puerto Vallarta, Mexico</option><option value="GDL">Guadalajara, Mexico</option><option value="BJX">Leon/Guanajuato, Mexico</option><option value="YXT">Terrace, BC</option><option value="YXS">Prince George, BC</option><option value="SLP">San Luis Potosi, Mexico</option><option value="YXU">London, ON</option><option value="YXX">Abbotsford, BC</option><option value="YXY">Whitehorse, YT</option><option value="YHM">Hamilton, ON</option><option value="CMH">Columbus, OH</option><option value="YYC">Calgary, AB</option><option value="YYG">Charlottetown, PE</option><option value="YYF">Penticton, BC</option><option value="PWM">Portland, ME</option><option value="AZA">Phoenix (Mesa), AZ</option><option value="GEG">Spokane, WA</option><option value="YHZ">Halifax, NS</option><option value="YYJ">Victoria, BC</option><option value="SMF">Sacramento, CA</option><option value="FCO">Rome, Italy</option><option value="YYT">St. John's, NL</option><option value="VCE">Venice, Italy</option><option value="AZS">Samana, Dominican Republic</option><option value="YYZ">Toronto, ON</option><option value="MAN">Manchester, United Kingdom</option><option value="YZF">Yellowknife, NT</option><option value="TPA">Tampa, FL</option><option value="SNA">Orange County - Anaheim, CA</option><option value="PHF">Newport News/Williamsburg, VA</option><option value="MBJ">Montego Bay, Jamaica</option><option value="PHL">Philadelphia, PA</option><option value="SNU">Santa Clara, Cuba</option><option value="KOA">Kona, Island of Hawaii, Hawaii</option><option value="ZLO">Manzanillo, Mexico</option><option value="BMI">Bloomington/Normal, IL</option><option value="PHX">Phoenix, AZ</option><option value="DAB">Daytona Beach, FL</option><option value="PIA">Peoria, IL</option><option value="MSP">Minneapolis-St. Paul, MN</option><option value="YKA">Kamloops, BC</option><option value="DAL">Dallas-Love, TX</option><option value="OGG">Kahului, Maui, Hawaii</option><option value="MCI">Kansas City, MO</option><option value="MSY">New Orleans, LA</option><option value="ECP">Panama City, FL</option><option value="BNA">Nashville, TN</option><option value="YKF">Kitchener/Waterloo, ON</option><option value="ALB">Albany, NY</option><option value="MCO">Orlando, FL</option><option value="BNE">Brisbane, QLD</option><option value="PIT">Pittsburgh, PA</option><option value="DAY">Dayton, OH</option><option value="LAS">Las Vegas, NV</option><option value="LAX">Los Angeles, CA</option><option value="TRI">Bristol/Johnson, TN</option><option value="ILM">Wilmington, NC</option><option value="JNU">Juneau, AK</option><option value="FWA">Fort Wayne, IN</option><option value="TRN">Turin, Italy</option><option value="MTY">Monterrey, Mexico</option><option value="YLL">Lloydminster, AB</option><option value="MUC">Munich, Germany</option><option value="MDT">Harrisburg, PA</option><option value="BOI">Boise, ID</option><option value="DSM">Des Moines, IA</option><option value="MDW">Chicago-Midway, IL</option><option value="DCA">Washington-National, DC</option><option value="YLW">Kelowna, BC</option><option value="ROA">Roanoke, VA</option><option value="CAE">Columbia, SC</option><option value="BOS">Boston, MA</option><option value="ROC">Rochester, NY</option><option value="CAK">Akron/Canton, OH</option><option value="MEM">Memphis, TN</option><option value="MEL">Melbourne, VIC</option><option value="ANC">Anchorage, AK</option><option value="YMM">Fort McMurray, AB</option><option value="IND">Indianapolis, IN</option><option value="SAN">San Diego, CA</option><option value="MEX">Mexico City, Mexico</option><option value="EVV">Evansville, IN</option><option value="UVF">Vieux Fort, St. Lucia</option><option value="DTW">Detroit, MI</option><option value="LTO">Loreto, Mexico</option><option value="SAT">San Antonio, TX</option><option value="ANU">St. John's, Antigua & Barbuda</option><option value="CRW">Charleston, WV</option><option value="SAV">Savannah, GA</option><option value="DUB">Dublin, Ireland</option><option value="MVY">Martha's Vineyard, MA</option><option value="SRQ">Sarasota/Bradenton, FL</option><option value="CSG">Columbus, GA</option><option value="PLS">Providenciales, Turks and Caicos</option><option value="BQK">Brunswick, GA</option><option value="EWN">New Bern, NC</option><option value="SBN">South Bend, IN</option><option value="EWR">Newark, NJ</option><option value="CCC">Cayo Coco, Cuba</option><option value="DUS">Dusseldorf, Germany</option><option value="OKC">Oklahoma City, OK</option><option value="HMO">Hermosillo, Mexico</option><option value="DEN">Denver, CO</option><option value="MGM">Montgomery, AL</option><option value="TUS">Tucson, AZ</option><option value="VIE">Vienna, Austria</option><option value="JAN">Jackson, MS</option><option value="GLA">Glasgow, United Kingdom</option><option value="SCL">Santiago, Chile</option><option value="LEX">Lexington, KY</option></select>
</div>
<div class="airportpicker-filter-wrapper fixed active" id="origin-picker">
<span class="twitter-typeahead" style="position: relative; display: inline-block;"><input type="text" aria-label="Start typing an origin and use up and down arrow keys to cycle through suggestions" style="outline: 0px; position: absolute; top: 0px; left: 0px; border-color: transparent; box-shadow: none; opacity: 1; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255);" class="tt-hint" readonly="" autocomplete="off" spellcheck="false" tabindex="-1" dir="ltr"><input placeholder="Enter origin or airport" type="text" id="origin-search" aria-label="Start typing an origin and use up and down arrow keys to cycle through suggestions" style="outline: 0px; position: relative; vertical-align: top; background-color: transparent;" class="tt-input" autocomplete="off" spellcheck="false" dir="auto"><pre aria-hidden="true" style="position: absolute; visibility: hidden; white-space: pre; font-family: "Noto Sans", "Noto Sans SC", "Noto Sans JP", Roboto, "Trebuchet MS", Arial, sans-serif; font-size: 17px; font-style: normal; font-variant: normal; font-weight: 400; word-spacing: 0px; letter-spacing: 0px; text-indent: 0px; text-rendering: auto; text-transform: none;">Seattle, WA
Моя текущая попытка:
flight_tab = driver.find_element_by_id('flights-tab')
flight_tab.click()
# Send origin input
clearInput = driver.find_element_by_id('origin-search')
clearInput.clear()
clearInput.send_keys("YYC")
wait = WebDriverWait(driver, 10)
origin_menu = driver.find_element_by_id("origin")
action = ActionChains(driver)
#hover on origin_menu first
action.move_to_element(origin_menu).perform()
#now find origin link and click
origin = wait.until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "YYC")))
origin.click()here
Ссылка на сайт, с которым я работаю
Решенные решения:
Щелкните по скрытой ссылке, используя элемент Selenium в Python , элемент не виден: элемент в настоящее время не виден и не может быть изменен - Selenium webdriver Как выбрать значение раскрывающегося меню с помощью Selenium с помощью Python?
Любая помощь будет потрясающей:)