![]() |
Unable to send text via sendkeys - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Unable to send text via sendkeys (/thread-12661.html) |
Unable to send text via sendkeys - SamLearnsPython - Sep-06-2018 Hi. This is a script to add image and text to wordpress. The adding images part works alright but I am unable to send the text via document.send_keys(my_text) because I get the selenium.common.exceptions.WebDriverException: Message: unknown error: keys should be a string error. I have tried downgrading selenium as well. I also did a print(my_text) and it printed the output text correctly so I know its getting picked correctly but not being sent.
from selenium.webdriver.common.keys import Keys import os from time import sleep import textract from selenium import webdriver browser = webdriver.Chrome('/usr/local/share/chromedriver') print() username = 'admin' #change it password = 'password' dir = 'Doc' dir2 = 'Images' all_files = os.listdir(dir+"/") doc_files = list(filter(lambda x: x[-4:] == '.odt', all_files)) browser.get('http://localhost/website/wp-login.php') print('\n-------------------------------') print('Getting into the WordPress ...') print('-------------------------------\n') user_field = browser.find_element_by_xpath('//form//input[@type = "text"]') user_field.click() user_field.send_keys(username) pass_field = browser.find_element_by_xpath('//form//input[@type = "password"]') pass_field.click() pass_field.send_keys(password) submit = browser.find_element_by_xpath('//form//input[@type = "submit"]') submit.click() print('+---------------------------+') print('| Login Successfull! |') print('+---------------------------+\n\n') sleep(2) edit_post = browser.find_element_by_xpath('//div[@id = "wpwrap"]//ul[@id = "adminmenu"]//a[@class="wp-has-submenu wp-not-current-submenu menu-top menu-icon-post open-if-no-js menu-top-first"]') edit_post.click() for x in doc_files: print('+-----------------------------------+') print('| Adding New Post |') new_post = browser.find_element_by_xpath('//div[@class = "wrap"]//a[@class="page-title-action"]') new_post.click() title = browser.find_element_by_xpath('//div[@id = "titlewrap"]//input[@name = "post_title"]') title.click() post_title = os.path.splitext(x)[0] title.send_keys((post_title+ " Images")) document = browser.find_element_by_xpath('//iframe[@id = "content_ifr"]') my_text = textract.process(dir+'/'+x) document.click() sleep(1) document.send_keys(my_text) insert_media = browser.find_element_by_xpath('//button[@id = "insert-media-button"]') insert_media.send_keys("\n") input_file = "//input[starts-with(@id,'html5_')]" image_files = os.listdir(dir2 + "/" + post_title+"/") for image in image_files: upload_button = browser.find_element_by_xpath(input_file).send_keys(os.getcwd() + "/" +dir2 + "/"+ post_title+"/"+ image) sleep(1) insert_images = browser.find_element_by_xpath('//button[@type = "button" and contains(text(),"Insert into post")]') sleep(2) insert_images.click() sleep(1) document.send_keys("\n") document.send_keys(Keys.CONTROL + Keys.END) document.send_keys("\n\n") sleep (5) submit = browser.find_element_by_xpath('//input[@type = "submit" and @value = "Publish"]') browser.execute_script("arguments[0].click();", submit) print('| Post Added Successfully! |') print('+-----------------------------------+\n\n') sleep(2) RE: Unable to send text via sendkeys - SamLearnsPython - Sep-08-2018 Bump! |