selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable - html

I'm programming for fun so I wanted to learn about selenium webdriver using twitter but I have a problem.
The problem comes when I try to put my text in the box of the tweet:
So I have to kind of activate the element that's on the box and that went good:
TBot = webdriver.Chrome()
twitter_box_act = Tbot.find_element_by_xpath('//div[#class="public-DraftEditorPlaceholder-inner"]')
Tbot.execute_script("arguments[0].click(), twitter_box_act)
But once i try to put some text on the box this error appears:
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
The code that I've used to try to put text on the box is the next:
tweet_entry = self.bot.find_element_by_xpath('//span[#data-text="true"]')
tweet_entry.send_keys("some text here")
So what I've tried is looking more deep in the code with F12 this is what I got:
I tried to put some time.sleep(x) between every step that didn't solve it.
I tried editing first the br tag and after that editing the span tag but I still had the same message error
I've been looking on the internet with Twitter projects with selenium as well but since they change the UI is not the same HTML body.
Am I missing something?
PS: I skipped the login part since that has nothing to do with the problem

You have tried change this line:
-->Tbot.execute_script("arguments[0].click(), twitter_box_act)
The error is for interactable, and you has interable in arguments.

Related

Selenium question: neither css selector or XPath can locate a visible and clickable web element

Here's the link to the website I'm working with: https://www.ftchinese.com/channel/stock.html
Apologies that the website is in Chinese. Basically I'm trying to get the web driver to click on the login button in the header (upper righthand side). the login button is located in the red box Then a pop up window should show up where you can enter email and password.
I tried locating the element by CSS selector: login = driver.find_element_by_css_selector('span.visitor-box > a[onclick]')
and by XPath: login = driver.find_elements(By.XPATH, '//a[#onclick]')
Both methods successfully located the login element, but when i did print(login.size,login.text), the returned height and width is 0 and text is empty. However, the login button is visible and there is no overlay. When i tried to click on the button, login.click(), it returns the error message "element not interactable".
I also tried the popular answers in similar posts - waiting time.sleep(5), maximizing/setting window sizedriver.maximize_window(), and scrolling to the element first driver.execute_script("arguments[0].scrollIntoView();", login), but had no luck. I'm not sure if it has anything to do with this particular website I'm working with, or the pop up window. Would appreciate any help!
Sharing a simple patch of code to log in to your site https://www.ftchinese.com/channel/stock.html
login_button=self.driver.find_element_by_xpath("//a[contains(text(),'登录')]")
login_button.click()
username=self.driver.find_element_by_xpath("//input[#name='username']")
username.click()
username.send_keys("{{enter username}}")
password=self.driver.find_element_by_xpath("//input[#name='password']")
password.click()
password.send_keys("{{enter password}}")
submit=self.driver.find_element_by_xpath("//input[#value='登录']")
submit.click()
Try this out and let me know if it worked for you. Cheers!
You can try with the below solution :
I am using Explicit wait, for page loading, and delay issue.
Launch the screen in full screen mode.
Do not use Chinese or English alphabets in locators.
Sample code :
driver.maximize_window()
driver.implicitly_wait(30)
driver.get("https://www.ftchinese.com/channel/stock.html")
wait = WebDriverWait(driver, 20)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[onclick*='overlay-login']"))).click()
wait.until(EC.element_to_be_clickable((By.ID, "ft-login-input-username"))).send_keys("abc#gmail.com")
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='password']"))).send_keys("etcasasd12#$")
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div[class^='login-btn'] input"))).click()
Imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
I Tried below xpath. And it clicked on the specified element.
driver.find_element_by_xpath("//span/a[contains(text(),'登录')]").click()

unable to find multiple existing element with selenium

here is the html code of the Links i am trying to click on (i dont know why selenium cant locate the link. My guess is, that there are X amounts of the link. The only difference is the string in the brackets of onclick.) Underneath i'll show you 2 examples of the html code. I'd like to click on all of them (in this case on both)!
Button or Link:
<td class="text-right">
Ansehen</td>
Button or Link:
<td class="text-right">
Ansehen</td>
here are my Attempts to click on the button:
driver.find_element_by_link_text("doRetrievePnr('DUA75J')").click()
driver.find_element_by_xpath("//a[#onclick='doRetrievePnr('DUA75J')']").click()
Here are the Errors i get:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"link text","selector":"doRetrievePnr('DUA75J')"}
selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression //a[#onclick='doRetrievePnr('DUA75J')'] because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//a[#onclick='doRetrievePnr('DUA75J')']' is not a valid XPath expression.
am I missing out on something?
EDIT
Heres a picture of the BUTTONS, the HTML CODE and my PYTHON CODE (lines 34 & 35)
As mentioned in the comments - getting all the items of a specific identifier can be done with find_elements_by_... (note find elements - it's plural)
That returns an array you can iterate through to interact with each element.
It looks like all your links have the same ID.
Something like this might work:
links = driver.find_elements_by_id('viewPnr')
for link in links:
link.click()
time.sleep(10) #replace this with what you want to do
Obviously if you're clicking links and the page changes this might not work after the first iteration. However, this is the concept on how you can get all objects and iterate through them.

Cant get tinymce to display

Im trying to install tinymce to use with my text editor to allow the user to have a text box just like the stack overflow one. I cant get it to display though
ive put this in the head of my index file
<script src='https://cloud.tinymce.com/stable/tinymce.min.js'></script>
<script src='https:https://cloud.tinymce.com/stable/tinymce.min.js'>
</script>
<script src="//tinymce.cachefly.net/4.1/tinymce.min.js"></script>
<script>
tinymce.init({selector:'infotextarea'});
</script>
then in my info page ive put
<textarea id="infotextarea">Your content here.
</textarea>
can anyone explain why its not displaying
It may be that at the time you run the tinymce.init function, it is not yet rendered and there is no textarea in the DOM.
Try debugging your code on the following line:
<script>
debugger;
tinymce.init({selector:'infotextarea'});
</script>
When the web's execution has stopped on that line, in the development console of your browser type the following:
$('#infotextarea').length
If the size is greater than 0, textarea exists at that moment and it is another problem, but if it shows 0 is that you have not yet created that view, this will help us get more information about your problem.
If you want to target a <textarea> by ID you need to use a valid CSS selector.
selector: "#infotextarea"
(note the # at the beginning of the string)
I would also note you appear to be loading TinyMCE 3 separate times - I have no idea why you would need to do that - loading it once should be sufficient
Its not a perfect answer to my question, but i used ckeditor and it worked perfectly.
I must have a mistake somewhere that i or my team could not find with tinymce

using innerHTML at custom tag in IE

I have a problem I just can't solve, and need your advice since I'm out of ideas:
Context: I'm using tinyMCE Editor on my website and developed a custom plugin to include external xml files. So far everything works as expected. The links to the external xml files are represented as span-Tags:
<span id="-[XML Document 1]-" title="erg" class="xml_embed xml_include">-[XML Document 1]-</span>
but only in the tinyMCE editor with a custom class (xml_include) to distinguish them from normal text and upon switching to the html/source code view or saving, those span tags get replaced to xi:include elements:
<xi:include xmlns:xi="http://www.w3.org/TR/XInclude" show="xml_embed" href="erg">-[XML Document 1]-</xi:include>
The text that was set as innerHTML ("-XML Document 1]-") for the span tag(s) serves as placeholder in the editor and gets moved to the xi:include tag(s) in the source view and serves as placeholder there also.
Now to the problem:
The code to transform span.xml_include to xi:include gets called before the source code popup is displayed:
ed.onPreProcess.add(function(ed, o) {
var elm;
var domelm;
//get all span.xml_include elements
tinymce.each(ed.dom.select('span.xml_include', o.node), function(n) {
//IE ignores innerHTML when created with tinymce.dom, therefore use native JS createElement method to tell IE that custom tag is valid HTML
if(tinymce.isIE)
{
domelm = document.createElement('xi:include');
domelm.setAttribute("xmlns:xi", "http://www.w3.org/TR/XInclude");
domelm.href = n.title;
domelm.innerHTML = n.innerHTML;
domelm.show = n.className.split(/\s+/)[0];
document.body.appendChild(domelm);
ed.dom.replace(domelm, n);
}
else
{
//ed = tinyMCE.activeEditor
elm = ed.dom.create('xi:include', {href: n.title, show: n.className.split(/\s+/)[0]}, n.innerHTML);
elm.setAttribute("xmlns:xi", "http://www.w3.org/TR/XInclude");
ed.dom.replace(elm, n);
}
});
});
this code works perfectly fine in FF and Chrome, but not in IE (I tested 7 & 8): in IE the innerHTML of the new element "domelm" can't be set. Either it stays blank or if set explicitly an error is thrown. n.innerHTML can be accessed. I get an "Unknown runtime error" for the line domelm.innerHTML = n.innerHTML;
What else did I try?
the native JS way: domelm.appendChild(document.createTextNode(n.innerHTML)); to create a text node and append it to the "domelm" with no success (getting error: "unexpected call to method or property access", that should be the translation from "Unerwarteter Aufruf oder Zugriff" (german version))
the tinyMCE API way: tinymce.DOM.setHTML(domelm, n.innerHTML); resulted in no error but also the usual blank innerHTML
the jQuery way: $('#domelm').html(n.innerHTML); or first var jQelm = $(domelm); then jQelm.text(...); or jQelm.html(...); doesn't matter, neither works, IE always returns "unexpected call to method" error in the jquery core, which I obviously won't touch..
the tinyMCE way of creating elements as seen in the "else" part of the if condition above..if domelm.innerHTML = n.innerHTML; isn't explicitly set, elm.innerHTML just stays blank, else the same errors as on the approaches above occur, therefore I could as well skip the if(tinymce.isIE) detection..
What else can I do? Suggestions?
I also made sure to properly declare the custom xml namespaces, changed the MIME-type to application/xhtml+xml instead of simply text/html, "announced" the xi:include node for IE with document.createElement('xi:include'); and generally changed the code to please IE..and this seems to be the last major bug I have to overcome..
I'm not sure if it's an error in my code since FF and Chrome work fine local and remote and don't show any errors..?
Any help is appreciated, I hope I provided enough context for you so that it's clear what I meant. and sorry for mistakes, English is not my first language :)
Ok, wrapping the custom element in a p/div/span tag finally did the trick: I used span to leave the formatting unmodified..here is what I did:
In the "if(tinymce.isIE) part of the onPreProcess function, before "xi:include" is created, a wrapper is needed:
var wrapper = document.createElement('span');
Appending the custom tag-element to the wrapper:
wrapper.appendChild(domelm);
and appending a textNode to the wrapper since appending it to the domelm throws errors:
wrapper.appendChild(document.createTextNode(n.innerHTML));
and finally append the wrapper to the dom and replace the "span" tag (n) with the wrapped "xi:include" (wrapper, span tag to be modified):
document.body.appendChild(wrapper);
ed.dom.replace(wrapper, n);`
The result is a custom "xi:include" tag in IE with the correct innerHTML:
<span><xi:include xmlns:xi="http://www.w3.org/TR/XInclude" href="eh" show="xml_embed">-[XML Document]-</xi:include></span>

Internet Explorer form input problem

I'm having a ton of problems with every version of IE, one of which is that IE7 won't register input in this text input field.
http://www.flightm8.com/redesign
I'm a bit nervous about posting the link since the site looks a mess and doesn't function properly in any version of IE at the moment, and it is still quite a way off being ready for public consumption. But if anyone can shed any light on this particular problem I'd very much appreciate it.
So the question is: What is causing this problem in IE7?
Update: I've also added an additional textfield at the bottom of the page to try and rule out any CSS wierdness that might be causing the problem.
<form method="post" action="nowhere.php">
<input type='text' name='test' value='testing' />
</form>
And I still can't enter any text, or select the text that is in there. I'm wondering now if it's a problem caused by running a standalone version of IE7 and IE6.
thanks
-t
the function causing problem is this one :
function modalAlert
the call that need to be debugged is this one :
modalAlert("NO SELECTIONS");
in
function findRoutes
the line that bug is :
$("#dialog").css("top", dTop);
first, you should avoid iframes when you can, why don't you do :
var message = $('<div></div>').load('/modal/"+modalpage);
instead of crappy code like this :
var iframe = "<iframe id='modal_frame' width='533' height='292' src='/modal/"+modalpage+"' >You didn't give me any information</iframe>"
If you don't need iframes, don't use them !
$('body').append(message);
I have IE7 on win xp (native), I was able to enter text but after a freeze (when you add all those markers), then when entering text and clicking on "find routes", there's a bug that i just explained to you ...
I would imagine it is because the input box doesn't have a 'name' field, which is used when posting form data.