Having trouble inputting into tinymce via selenium - python

In selenium i am trying to enter text into the tinymce text area, but i am having trouble selecting the text area to input the text. Is there a way to select the text area behind tinymce or anyway to select tinymce so i can enter text. thanks

Use command: runScript
Target: tinyMCE.get('text_area_id').setContent('Your text here')
or you can use tinyMCE.activeEditor.setContent('Your text here') which will select either the first or the last mceEditor, I forget..

You may use
tinymce.get('your_editor_id').focus();
In case you have one single editor on your page you may also use
tinymce.editors[0].focus();

driver.execute_script("tinymce.get('{0}').focus()".format('id_of_textarea'))
driver.execute_script("tinyMCE.activeEditor.setContent('{0}')".format('your text here'))
it works for me
(cant remember where i saw it thought)

Related

Python Selenium pulling child property from parent?

I'm trying to scrape a webform for text in specific fields however i can't do it with xpath because some forms are missing fields which won't be included in the page when it loads (i.e. if /html/blah/blah/p[3] is the initials field for one form it might be first name on another form but have the same xpath. The structure for the fields is like this:
<p><strong>Initials:</strong> WT</p>
so using python selenium i'm doing
driver.find_element_by_xpath("//*[contains(text(), 'Initials:')]") which does successfully pull the "Initials:" text between the strong tags but i specifically need the child text after it, in this case WT. It has the attribute "nextSibling.data" which contains the WT value but from my googling i don't think its possible to pull that attribute with python selenium. Does anyone know a way to pull the WT text following the xpath query?
The 'WT' text is in a weird spot. I don't think it is actually a sibling per-se. The only way I know to grab that text would be to use p_element.get_attribute('outerHTML'), which in this instance should grab the string '<p><strong>Initials:</strong> WT</p>'. I doubt this is the cleanest solution, but here's a way to parse that text out:
strong_close_tag = '</strong>'
p_close_tag = '</p>'
p_element = driver.find_element_by_xpath("//*[contains(text(), 'Initials:')]/parent")
print(p_element.get_attribute('outerHTML')[text.index(strong_close_tag)+len(strong_close_tag):text.index(p_close_tag)])
OR -- use p_element.get_attribute('innerHTML'), which should return just <strong>Initials:</strong> WT. Then, similarly, grab the text after the </strong> closing tab, maybe like this:
p_element = driver.find_element_by_xpath("//*[contains(text(), 'Initials:')]/parent")
print p_element.get_attribute('innerHTML').split("</strong>",1)[1]

Selenium error when interacting with textarea

I try to enter text into text area on the web i am using selenium to do this but when i try to input into textarea it fails with error:"selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable".
However when i try to put text into field it works normaly
driver.find_element_by_xpath('//textarea[#class = "Ypffh"]').send_keys(text);
You could try it with javascript:
driver.execute_script('document.querySelector("textarea.Ypffh").innerText = "xxx"')
Sometimes you might need to click on the textarea before you can interact with it.
I would try this:
driver.find_element_by_xpath('//textarea[#class = "Ypffh"]').click();
driver.find_element_by_xpath('//textarea[#class = "Ypffh"]').send_keys(text);
If that doesn't work, I would check to see if there's a hidden tag near the textarea that may function as the input receiver rather than the textarea itself. Sometimes you see cases where a textarea is just a visual representation, but doesn't actually receive text, so there may be a hidden that receives text instead.

Selenium find element by text with &#65279?

I'm pretty new to test automation so how I can click some a link if I know only partial text.
I know that there is find_element_by_partial_link_text but there are words in the code that appear randomly . I am not able to click by partial text if it appears , for instance:
I know only word Example
<a class="name-link">First Example</a>
I am unable click by class because there are a lot of the same class.
So is there any way to ignore ?
I am writing in python.
Try to click() the element through :
Partial Link Text
driver.find_element_by_partial_link_text("First Exa").click()
XPath
driver.find_element_by_xpath("//a[#class='name-link' and contains(.,'First Exa')]").click()
If you want to match link by word "Example" you can try to use search by XPath
driver.find_element_by_xpath('//a[contains(., "Exa") and contains(., "mple")]').click()
But note that it also will match, for example, link "Examine the sample"
If this not an option for you, you might need to use more complex xpath:
//a[starts-with(substring-after(., " "), "Exa") and substring(substring-after(., " "), 5) = "mple"]
to match string in format "(string)(space)Exa(extra non-ascii character)mple"
Also note that method find_by_link_text()/find_by_partial_link_text() searches for text as it appears on page, but not as it appears in HTML source code, so you can just copy text from page rendered by browser and use it as argument for driver.find_element_by_partial_link_text()

find_element_by_partial_link_text ascii code issue

http://www.m2sys.com/.
When I click on CloudApper™ under Solutions I get an ascii code error.
I find the element using:
driver.find_element_by_partial_link_text('CloudApper™')
How can I click the partial link?
Just ignore the TM in superscript while searching for CloudApper™.
driver.find_element_by_partial_link_text('CloudApper')
There are two instances by link text CloudApper™ in the target page. You can use this for finding the link cloudApper located below solutions. driver.find_element_by_xpath("//ul[#id='mobile-advanced']//a[contains(#href,'cloudapper')]")
CloudApper™ is a label, you have to click logo, use this xpath
//a[#href='http://www.m2sys.com/cloudapper-modularized-framework-enterprise-cloud-application/']
Try the following,
first, you need to interact with the menu:
driver.find_element_by_id("menu-item-15554").click();
then click on the actual element:
driver.find_element_by_xpath("//a[contains(#href, 'cloudapper-modularized-framework-enterprise-cloud-application')]").click();

How to check alignment of text using selenium RC

verify alignment of text or any other element in web page using selenium rc.
i use python,
is there any budy who can help with this.
you can utilize getAttribute command for example
String align = selenium.getAttribute("ele_locator#align");
In case text alignment is coded directly in HTML you could do what you want using the assertElementPresent() method and a suitable XPath locator. For example to check the following text
<p id="paragraph" align="right">Text text text text text text text</p>
you could use
selenium.isElementPresent("//p[#id='paragraph' and #align='right']");

Categories

Resources