I'm trying to send a very large html part into a rich text box, I've managed to send in part of the html code but the problem is that the links inside the html get opened whenever I send the code
This is what the html code that I'm trying to send looks like:
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600|Roboto+Condensed:300,400,700" rel="stylesheet" />
<link href="https://..." />
<link href="https://cldup.com/....css" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css?family=Bree+Serif|Cairo|Saira+Semi+Condensed:400,700|Ubuntu" rel="stylesheet" />
<div class="wholeWidth">
<header>
<div class="containerWidth"><img alt="banner" src="https://..." /></div>
</header>
<div class="containerWidth">
<nav class="navbar navbar-default">
<div class="container text-center">
<div class="navbar-collapse" id="navbar">
<ul class="nav navbar-nav">
<li><a target="_blank" href="http://...">Geschäft</a></li>
<li><a target="_blank" href="https://...">NEUE ANKUNFT</a></li>
<li><a target="_blank" href="....</a></li>
<li><a target="_blank" href="....</a></li>
<li><a target="_blank" href="http://contact.ebay.de/ws/eBayISAPI.dll?FindAnswers&frm=284&requested=der_old_shatterhand&iid=-1">Kontakt</a></li>
</ul>
</div>
</div>
</nav>
</div>
<div class="containerWidth hidden-sm hidden-xs"><img alt="30days" class="img-responsive" src="https://..." /></div>
<div class="content">
<div class="listing_row1">
<div class="containerWidth">
<div class="row">
<div class="containerWidth"><img alt="banner" src="..." /></div>
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600|Roboto+Condensed:300,400,700" rel="stylesheet" />
<link href="https://..." rel="stylesheet" />
<link href="https://..." />
<link href="https://fonts.googleapis.com/css?family=Bree+Serif|Cairo|Saira+Semi+Condensed:400,700|Ubuntu" rel="stylesheet" />
<div class="wholeWidth">
<header>
<div class="containerWidth"><img alt="banner" src="https://..." /></div>
This is what the html that gets sent looks like, it also opened all of the links in the html:
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600|Roboto+Condensed:300,400,700" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cldup.com/BIUxxmE1z4.css" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css?family=Bree+Serif|Cairo|Saira+Semi+Condensed:400,700|Ubuntu" rel="stylesheet" />
<div class="wholeWidth">
<header>
<div class="containerWidth"><img alt="banner" src="https://cldup.com/00FhLi9aZS.png" /></div>
</header>
<div class="containerWidth">
<nav class="navbar navbar-default">
<div class="container text-center">
<div class="navbar-collapse" id="navbar">
<ul class="nav navbar-nav">
</ul>
</div>
</div>
</nav>
</div>
</div>
This is the python code I used to upload the html, is there any way to resolve this?
my_html = "html code"`
rich_text_box = driver.find_element_by_class_name("cke_source.cke_reset.cke_enable_context_menu.cke_editable.cke_editable_themed.cke_contents_ltr")
rich_text_box.clear()
rich_text_box.send_keys(my_html)
I also tried to execute a javascript in order to send the html, but it does not recognize "my_html".
iframe = driver.find_element_by_class_name("cke_wysiwyg_frame.cke_reset")
driver.switch_to.frame(iframe)
html_body = driver.find_element_by_css_selector('body')
driver.execute_script("arguments[0].innerHTML= my_html", html_body)
This is the error I get when I try to use javascript:
raise exception_class(message, screen, stacktrace) selenium.common.exceptions.JavascriptException: Message: javascript error: my_html is not defined (Session info: chrome=88.0.4324.182)
You have to send your html code through arguments[1]
like this if you want to inject it as a script :
driver.execute_script("arguments[0].innerHTML= arguments[1]", html_body, my_html)