I am facing a rare kind of issue while Automating through Selenium/Python while trying to fill out two fields on a website. My script fills out the first field i.e. ORIGIN CITY pretty fine. I have induced WebDriverWait for the second field DELIVERY ADDRESS.
My guess the DELIVERY ADDRESS field is pretty much clickable even before the waiter is induced.
But the ORIGIN CITY field have a JavaScript associated through onchange
event as follows :
onchange="javascript:setTimeout('__doPostBack(\'DrpCity\',\'\')', 0)"
ORIGIN CITY HTML :
<li>
<div class="form-group">
<select name="DrpCity" onchange="javascript:setTimeout('__doPostBack(\'DrpCity\',\'\')', 0)" id="DrpCity" class="inputStyle">
<option selected="selected" value="0">Origin City</option>
<option value="3">Bangalore</option>
<option value="6">Chennai</option>
<option value="8">Delhi - NCR</option>
<option value="10">Hyderabad</option>
<option value="7">Kochi</option>
<option value="12">Kolkata</option>
<option value="13">Mumbai</option>
<option value="15">Pune</option>
</select>
<span id="ReqCity" style="color:Red;visibility:hidden;">Select your city !</span>
</div>
</li>
DELIVERY ADDRESS HTML :
<li>
<div class="form-group">
<div class="" id="div_AddPopup" style="display: none;">
*Cars will not be delivered at Metro Stations, Malls or Public Place.
</div>
<input name="txtPickUp" type="text" id="txtPickUp" class="inputStyle locMark" placeholder="Delivery Address" onfocus="showOnKeyPress(); return true;" onblur="hideOnKeyPress(); return true;">
<span id="ReqPickUp" style="color:Red;visibility:hidden;">Enter Delivery Address !</span>
</div>
</li>
Once the JavaScript finishes it clears up the text from the DELIVERY ADDRESS field.
I did had a look at the Java Client's ExpectedConditions as jsReturnsValue which is not there for the Selenium Python Client.
Website : https://www.avis.co.in/
My Code :
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Firefox()
driver.get("https://www.avis.co.in")
mySelect = Select(driver.find_element_by_id("DrpCity"))
mySelect.select_by_visible_text("Pune")
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,"//input[@id='txtPickUp']"))).send_keys("XYZ")
Any suggestions will be helpful.