Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

handle tinymce window with python, selenium and phantomjs

I have the following code for logging in on a site and post something in a forum

driver = webdriver.PhantomJS()

Username = "username"
Password = "password"

driver.get(LoginPage)
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "login")))

driver.find_element_by_name("usr").send_keys(Username)
driver.find_element_by_name("pas").send_keys(Password)

driver.find_element_by_id("login").click()

payload = "some text"

driver.get(ForumPage)
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "submitbtn")))


driver.switch_to_frame("tinymcewindow_ifr")
driver.find_element_by_id("tinymce").clear()
driver.find_element_by_id("tinymce").send_keys(payload)
driver.switch_to_default_content()

driver.find_element_by_id("submitbtn").click()

driver.quit()

When I try and use another browser (like firefox) it works fine, but with phantom nothing is posted.

What I believe could be the problem is that phantom doesn't fill in the tinymce textarea as i want it to. is there any fix for this problem?

like image 634
user3209502 Avatar asked Jan 18 '14 11:01

user3209502


1 Answers

Use the tinymce js API.

Replace

driver.switch_to_frame("tinymcewindow_ifr")
driver.find_element_by_id("tinymce").clear()
driver.find_element_by_id("tinymce").send_keys(payload)
driver.switch_to_default_content()

with

driver.execute_script("tinyMCE.activeEditor.setContent('%s')" % payload)
like image 162
Jay Avatar answered Oct 31 '22 08:10

Jay