2

I am trying to post something on http://indianrailforums.in using selenium script. I am able to login and reach this page: http://indiarailinfo.com/blog using the selenium script, but after I click post button I am not able to send text in the text area.

This is my code:

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Firefox()

driver.get("http://indiarailinfo.com")
element = driver.find_element_by_name("e")
element.send_keys("[email protected]")
element = driver.find_element_by_name("p")
element.send_keys("suvrit")
element.submit()
driver.get("http://indiarailinfo.com/blog")
element = driver.find_element_by_link_text('Post')
element.click()
element = driver.find_element_by_xpath("/html/body/div[1]/div[5]/table/tbody/tr/td[1]/div[1]/div[1]/div/div/form/textarea")
#element.sendKeys(Keys.HOME + "abc");
#element = driver.find_element_by_name("TrainBlog")
element.send_keys("suvrit")
#driver.quit()

EDIT: Issue solved by using submit button and using driver.implicitly_wait(10) just before calling xpath

3
  • When you say you are "not able to send text" - what actually happens? What errors or behaviour do you see? Commented Mar 21, 2015 at 20:14
  • Nothing happens after the post option is clicked a text area comes and then it all stops Commented Mar 21, 2015 at 20:17
  • whereas what I want is I want to write in that text area which comes after clicking post Commented Mar 21, 2015 at 20:29

2 Answers 2

1

I was able to post with PhantomJS driver. It should work with Firefox either.

My code is:

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.PhantomJS()

driver.get("http://indiarailinfo.com")
element = driver.find_element_by_name("e")
element.send_keys("[email protected]")
element = driver.find_element_by_name("p")
element.send_keys("suvrit")
element.submit()
driver.get("http://indiarailinfo.com/blog")
element = driver.find_element_by_link_text('Post')
element.click()
element = driver.find_element_by_xpath("/html/body/div[1]/div[5]/table/tbody/tr/td[1]/div[1]/div[1]/div/div/form/textarea")
print element.tag_name
#element.sendKeys(Keys.HOME + "abc");
#element = driver.find_element_by_name("TrainBlog")
element.send_keys("chuh-pook")
element.submit()
#driver.quit()
Sign up to request clarification or add additional context in comments.

Comments

0

The problem is that you have not submitted the form. Either call submit():

element = driver.find_element_by_xpath("/html/body/div[1]/div[5]/table/tbody/tr/td[1]/div[1]/div[1]/div/div/form/textarea")
element.send_keys("suvrit")
element.submit()  # it would find the parent form and submit it

Or, click the post button:

post = driver.find_element_by_css_selector('input.postbtn')
post.click()

2 Comments

NO luck still the same. And yes I am getting an error which is this pastebin.com/ngM2fwfZ
Done by adding the submit as well as driver.implicitly_wait(10) just before x path.Thanx a lot

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.