4

I am working on a web scraper where I need to click the submit button to trigger a JavaScript script to load a page. I am not able to identify the right tag and perform the click() function. I am thinking this has to do something with the aria-hidden="true" tag. Can you please let me know how we can achieve this?

Here is the page_source section for the button:

<div>   
     <button type="button" class="btn btn-primary" onclick="javascript:document.forms[0].submit();">
        <span class="glyphicon glyphicon-search" aria-hidden="true"></span>Search
     </button>
     &nbsp;
</div>

Here is the code that I have:

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
import time

driver = webdriver.PhantomJS(executable_path='C:/Users/50178/Documents/learn/pracpy/phantomjs-2.1.1-windows/phantomjs-2.1.1-windows/bin/phantomjs.exe')
#driver = webdriver.Chrome(executable_path='C:/Users/50178/Documents/learn/pracpy/ChromeDriver/chromedriver.exe')
driver.get("http://www16.co.hennepin.mn.us/cfrs/search.do")
driver.implicitly_wait(5)
driver.find_element_by_css_selector("input[type='radio']").click()
print(driver.page_source)
print (driver.find_element_by_xpath('.//div[@class="btn btn-primary"]'))
driver.close()

1 Answer 1

2

"btn btn-primary" is a class name of button, but not div. Try

//button[@class="btn btn-primary"]

or

//button[.="Search"]
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot Andersson!! You are awesome.

Your Answer

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.