这是我尝试从http://www.flypeach.com/pc/en
获取数据的网站但是,在尝试选择“FROM”位置时,我只能点击以显示包含代码的位置选项表单:
driver = webdriver.Chrome()
driver.get("http://www.flypeach.com/pc/en")
inputFrom = driver.find_element_by_id("inputFrom")
inputFrom.click()
但未能在表单中选择任何具有多种方法的位置。例如
ActionChains
或execute_script
,任何人都可以提供帮助吗?
以下是尝试代码:
TPE = driver.find_element_by_id("TPE")
ActionChains(driver).click(TPE).perform()
或
TPE = driver.find_element_by_xpath("//*[@id='TPE']/a")
TPE.click()
或
driver.execute_script("arguments[0].style = {};", TPE)
答案 0 :(得分:2)
首先你必须点击From元素,然后你从新的弹出窗口'dialogFrom'中选择元素
这是脚本:
WebElement locationElm = driver.findElement(By.xpath(".//*[@id='inputFrom']"));
locationElm.click();
WebElement fromElm = driver.findElement(By.xpath(".//*[@id='dialogFrom']//*[@id='KIX']/a"));
formElm.click();
希望这会有所帮助
答案 1 :(得分:1)
请看这个网站的源代码,有一个完整的"来自"和"到"机场。
例如:
<div id="fromDialogTemplate" style="display:none;">
<div class="airportList dialog_3columns">
<div class="col_1 c1">
<div class="country">Japan</div>
<ul>
<li id="KIX"><a href="KIX">Osaka, Kansai (KIX) </a></li>
<li id="CTS"><a href="CTS">Sapporo, ShinChitose (CTS) </a></li>
<li id="SDJ"><a href="SDJ">Sendai, Sendai (SDJ) </a></li>
<li id="NRT"><a href="NRT">Tokyo, Narita (NRT) </a></li>
<li id="HND"><a href="HND">Tokyo, Haneda (HND) </a></li>
<li id="MYJ"><a href="MYJ">Matsuyama, Matsuyama (MYJ) </a></li>
<li id="FUK"><a href="FUK">Fukuoka, Fukuoka (FUK) </a></li>
<li id="NGS"><a href="NGS">Nagasaki, Nagasaki (NGS) </a></li>
<li id="KMI"><a href="KMI">Miyazaki, Miyazaki (KMI) </a></li>
<li id="KOJ"><a href="KOJ">Kagoshima, Kagoshima (KOJ) </a></li>
<li id="OKA"><a href="OKA">Okinawa, Naha (OKA) </a></li>
<li id="ISG"><a href="ISG">Ishigaki, Ishigaki (ISG) </a></li>
</ul>
</div>
<div class="col_1 c2">
<div class="country">Korea</div>
<ul>
<li id="ICN"><a href="ICN">Seoul, Incheon (ICN) </a></li>
<li id="PUS"><a href="PUS">Busan, Gimhae (PUS) </a></li>
</ul>
<div class="country">HongKong</div>
<ul>
<li id="HKG"><a href="HKG">HongKong, HongKong (HKG) </a></li>
</ul>
<div class="country">Taiwan</div>
<ul>
<li id="TPE"><a href="TPE">Taipei, Taoyuan (TPE) </a></li>
<li id="KHH"><a href="KHH">Kaohsiung, Kaohsiung (KHH) </a></li>
</ul>
<div class="country">China</div>
<ul>
<li id="PVG"><a href="PVG">Shanghai, Pudong (PVG) </a></li>
</ul>
</div>
<div class="col_1 c3">
<div class="country">Thailand</div>
<ul>
<li id="BKK"><a href="BKK">Bangkok, Suvarnabhumi (BKK) </a></li>
</ul>
</div>
</div>
</div>