I've written a script in python using selenium to get to a specific page. There are five steps to hurdle to reach there. First my browser has to click the "search by address" button then input the "street name" in a box and "street address" in the corresponding box and clicking the search button to get to the target page. However, I get an error in my first attempt while clicking on the "search by address" button. It seems that I did it accordingly but can't figure out where I'm making mistakes. Thanks in advance to take a look into it. The script I'm trying with:
from selenium import webdriver
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.Chrome()
driver.get("http://hcad.org/quick-search/")
wait = WebDriverWait(driver, 10)
driver.find_element_by_id("s_addr").click()
driver.find_element_by_name('stnum').send_keys('8227')
driver.find_element_by_name('stname').send_keys('FINDLAY ST')
driver.find_element_by_link_text("Search").click()
driver.quit()
Elements within which the button for "search by address" id is found:
<tbody><tr>
<td class="auto-style1"></td>
<td width="15" align="left" valign="top" class="auto-style1"></td>
<td width="600" align="left" valign="top" class="auto-style1">
<input type="submit" id="s_acct" value="Search By Account">
<input type="submit" id="s_addr" value="Search By Address">
<input type="submit" id="s_name" value="Search By Owner Name"><table>
<form id="search_button" name="search_button" action="/records/QuickSearch.asp" method="post"></form>
Elements within which the rest keywords to fill in the box:
<tr align="middle">
<td colspan="1">
<select name="TaxYear">
<option value="2017">2017</option>
</select></td>
<td align="middle">
<input name="stnum" size="5" maxlength="5"></td>
<td align="middle">
<input name="stname" maxlength="24">
</td><td align="middle">
<nobr><input type="submit" value="Search"></nobr>
</td>
</tr>
The error I'm getting:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element:
1 Answer 1
You need to wait for the iframe
to be available and when it's available switch to it.
...
wait = WebDriverWait(driver, 10)
element = wait.until(EC.presence_of_all_elements_located((By.TAG_NAME, 'iframe')))
driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))
driver.find_element_by_id("s_addr").click()
driver.find_element_by_name('stnum').send_keys('8227')
driver.find_element_by_name('stname').send_keys('FINDLAY ST')
...
Also, using xpath seems like a more convenient way to select the search button.
driver.find_element_by_xpath("//input[@value='Search']").click()
driver.quit()
1 Comment
Explore related questions
See similar questions with these tags.