1

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">&nbsp;
<input type="submit" id="s_addr" value="Search By Address">&nbsp;
<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:
asked Aug 8, 2017 at 2:37

1 Answer 1

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()
answered Aug 8, 2017 at 3:21

1 Comment

Thanks Oluwafemi Sule, for your effective answer. I forgot about iframe for a while. It did the trick.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.