I'm creating a test for the forum and I would like to test the forum BB code. I have a BB code like this,
[B][FONT=Trebuchet MS][SIZE=7]Meteor[/SIZE][/FONT][/B]
[COLOR=#000000][FONT=Verdana][I][B][SIZE=4]n: [/B][/I][/FONT]
[S][B][FONT=Verdana]ki[/SIZE][/FONT][/B][/S][/COLOR]
[URL='https:///coral-lps-6/']
[FONT=Impact][SIZE=7][COLOR=#F41600][U]CLICK HERE TO BUY![/U][/COLOR][/SIZE][/FONT][/URL]
I'm trying to populate this code in to the text area(wrapped in p tag) using the following way,
messageBox = self.browser.find_elements_by_css_selector('.message-editorWrapper p')[0]
code = r"{}".format(bb_code)
self.browser.execute_script("arguments[0].innerHTML = '"+code+"'", messageBox)
I'm getting this error
Traceback (most recent call last): File "login.py", line 51, in bot.postRequest() File "login.py", line 31, in postRequest self.browser.execute_script("arguments[0].innerHTML = '"+code+"'", messageBox) File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 636, in execute_script 'args': converted_args})['value'] File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: Runtime.evaluate threw exception: SyntaxError: Invalid or unexpected token (Session info: chrome=70.0.3538.77) (Driver info: chromedriver=73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72),platform=Linux 4.15.0-66-generic x86_64)
But when I use simple text that is working fine. So how I can add the BB CODE in the forum to test that it is working or not using selenimum.
' 'ininnerHTML='...'but inside BB code you have also'in[URL='https:///coral-lps-6/']- maybe it makes problem. It can create incorrect JavaScript code. Maybe you should use" "ininnerHTML="..."or in BB code. - furasr"{}".format(bb_code)because it add nothing tobb_code- it will not add" "to code. - furas