0

I'm trying to scrape data from this web page... "http://agmarknet.nic.in/mark2_new.asp"

I need to type in "banana" in the commodity search and click the "Go" button.

With the help of Stack Overflow, I'm able to bring up Firefox, type in "Banana"...but the "Go" button (Go3 based on the inspection) WILL NOT FIRE!!

I've tried element.click(), I've tried ActionChains, I've tried moving the cursor to the element, I've verified it's enabled. It just will not go to the next search page.

The OTHER search button (B1...which is a generic search) sort of works...except that when selenium clicks it, it brings up a different page than when I click it manually...so that's weird too.

I DON'T get any errors...it just does not go to the next page.

Thanks in advance for any help you can offer. It's driving me crazy!

def SLEEP(num):
    for i in range(0,num,1):
        print ".",
        time.sleep(1)

def click_button(driver, button_name):
    assert driver.find_element_by_name(button_name)
    button = driver.find_element_by_name(button_name)

    if button.is_enabled():
        print "it is enabled"
    else:
        print "IT IS NOT ENABLED"

    # Try with element
    button.click()
    #Try with action chain
    action = ActionChains(driver)
    action.move_to_element(driver.find_element_by_name(button_name))
    action.click(driver.find_element_by_name(button_name))
    action.perform()

# WORKS
driver = webdriver.Firefox()
driver.get("http://agmarknet.nic.in/mark2_new.asp")
SLEEP(5)
assert "AG" in driver.title
print driver.title

# WORKS
textinput = driver.find_element_by_name('cmm')
textinput.send_keys("banana")
SLEEP(5)

# SORT OF WORKS (brings up unexpected page)
button_name = "B1"
click_button(driver, button_name)

# DOES NOT WORK
button_name = "Go3"
click_button(driver, button_name)
1
  • I concur with alecxe that your problem cannot be reproduced. Commented Mar 5, 2014 at 17:37

1 Answer 1

2

button.click() works for me. Note that you don't need to put time.sleep between actions:

from selenium import webdriver


driver = webdriver.Firefox()
driver.get("http://agmarknet.nic.in/mark2_new.asp")

textinput = driver.find_element_by_name('cmm')
textinput.send_keys("banana")

button_name = "Go3"
button = driver.find_element_by_name(button_name)
button.click()

Also, instead of click() you can push space button:

from selenium.webdriver.common.keys import Keys

...

button.send_keys(Keys.SPACE)

Hope that helps.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! Its good to know. Maybe it's because I'm running out of Eclipse. Let me try it from the command line...
I swapped to phantomjs and it works. No idea whats wrong with my Firefox.

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.