Can't fill in the Hidden text area element - python

F1, need some help or hints with Hidden element using Robotframework.
The problem consist that to fill any text in the text area, I need to change the state of text area from display:none; to display:block;
Needed text area for input
Code that I see from WebDev Tool
The code itself:
<div class="col-md-12">
<div class="cazary" style="width: 664px;">
<div class="cazary-commands-wrapper">
<ul class="cazary-commands-list">
<li unselectable="on" title="Size" class="cazary-command-fontsize">Size</li>
</ul>
<ul class="cazary-commands-list">
<li unselectable="on" title="Foreground Color" class="cazary-command-forecolor">Foreground Color</li>
</ul>
<ul class="cazary-commands-list">
<li unselectable="on" title="Background Color" class="cazary-command-backcolor">Background Color</li>
</ul>
<ul class="cazary-commands-list">
<li unselectable="on" title="Remove Format" class="cazary-command-removeformat">Remove Format</li>
</ul>
</div>
<iframe class="cazary-edit" src="javascript:" style="height: 39px;"></iframe>
<textarea id="summernote" class="required-preview field cazary-source" placeholder="Tell us all about your Advertisement. This description will be prominently displayed in your Advertisement notice. Feel free to adjust the fonts and background colour too." name="observations" cols="50" rows="10" style="display: none;"></textarea>
</div>
My Robotframework code tries:
Select Frame //iframe[#class="cazary-edit"]
# First try
Input text //textarea[#id="summernote"] ${UniversalVariableforName}
# Second try
Input text //iframe[#class="cazary-edit"] ${UniversalVariableforName}
# Third try
Input text //div[#class="cazary"]//iframe[#class="cazary-edit"] ${UniversalVariableforName}
# Fourth try
Input text //body[#class="empty"] ${UniversalVariableforName}
# Fifth try
Input text //iframe[#class="cazary-edit"]//body[#class="empty"] ${UniversalVariableforName}
Errors that were returned:
image
May be there is a solution with Execute Javascript keyword?

The concerned <textarea> is outside of the <iframe class="cazary-edit">. Hence we don't need to switch to the <iframe>
To send the text to the Input field you can try to :
Use xpath as :
"//textarea[#class='required-preview field cazary-source' and #id='summernote']"
Click the Input field first.
Next Clear the Input field.
Finally try to send the text.
Update :
As the concerned textarea have the style attribute set as "display: none;", we have to change to "display: block;" through JavascriptExecutor then send the text.
Python Sample Code :
driver.execute_script("document.getElementById('ID').style.display='block';")

Related

How to get all text in inside div parent with xpath

I want to get all text inside a div with xpath
Here HTML code:
<div class="JobDescriptionsc__DescriptionContainer-sc-1jylha1-2 dGyoDf">
<div class="DraftEditorContainersc__DraftEditorContainer-sc-1x4uima-0 cGUaQf">
<div class="DraftEditor-root">
<div class="DraftEditor-editorContainer">
<div class="public-DraftEditor-content" contenteditable="false" spellcheck="false" style="outline:none;user-select:text;-webkit-user-select:text;white-space:pre-wrap;word-wrap:break-word">
<div data-contents="true">
#Here the all text
<div class="" data-block="true" data-editor="d54la" data-offset-key="bhkoa-0-0">
<div data-offset-key="bhkoa-0-0" class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr">
<span data-offset-key="bhkoa-0-0" style="font-weight:bold">
<span data-text="true">Job Description:</span>
</span>
</div>
</div>
<div class="" data-block="true" data-editor="d54la" data-offset-key="51e5u-0-0">
<div data-offset-key="51e5u-0-0" class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr">
<span data-offset-key="51e5u-0-0">
<span data-text="true">ยท Identify & developed application base on predefined business requirements.</span>
</span>
</div>
</div>
...
#there's more, I'm just showing you a few
</div>
</div>
</div>
</div>
</div>
</div>
This my XPath code:
dom_job.xpath('//*[#class="DraftEditorContainersc__DraftEditorContainer-sc-1x4uima-0 cGUaQf"]//text()')
I need the all text inside the div parent with xpath, can it?
I'm assuming the Python module which provides your XPath interpreter supports XPath version 1. Your XPath expression below returns the set of all text nodes which are descendants of the div element:
//*[#class="DraftEditorContainersc__DraftEditorContainer-sc-1x4uima-0 cGUaQf"]//text()
You should be able to iterate over all that collection of text nodes, and concatenate them into a single string, in Python.
But it's simpler, if you want the concatenated value of the text nodes within a particular div, to just apply the XPath string() function to the div; e.g.:
string(//*[#class="DraftEditorContainersc__DraftEditorContainer-sc-1x4uima-0 cGUaQf"])
See https://www.w3.org/TR/1999/REC-xpath-19991116/#function-string
Note that, in XPath 1, if you apply the string() function to a larger set of nodes (such as the set of text nodes returned by your first query), the function will return the string value of just the first node.

find button that is within 3 divs selenium python

I am trying to find the text of a button. here is the html layout.
<div id="fulfillment-add-to-cart-button">
<div class="fulfillment">
<div>
<div style="position:relative">
<button class="btn ban-disabled"> Sold Out </button>
</div>
</div>
</div>
</div>
Here is what I have
driver.find_elements_by_xpath("//div[#id='fulfillment-add-to-cart-button']/div/div/div/button[0]")
I keep returning a empty array. I've tried also finding the button with the button classname however that also returns an empty array.
The button is a single element, correct? So you would find by element, not elements.
Try this, to search for that specific text within that button
button_elem = driver.find_element_by_xpath("//div[#id='fulfillment-add-to-cart-button']//button")
print(button_elem.text)
If that doesn't work we may need to see more of the HTML that surrounds that section

how to locate and click an element by div input_title?

I am trying to locate and click an element by text. The reason is that the id and location of the element are dynamic but the text is always the same.
Here it is how look like as a HTML:
<div class="p-r" input-title="I want to identify by text here">
<!---->
<div class="skDeleteBtn skRequired">
<input class="input radio--big ng-untouched ng-pristine ng-valid" data-cname="radibutton" type="radio" id="z1jcfqy9">
<label class="label label--radio-big" for="z1jcfqy9" style="color: inherit;">
<span></span>I want to identify by text here
<i class="d-ib va-m ml-3">
<sk-tooltip><!---->
</sk-tooltip>
</i>
</label>
</div>
</div>
I want to identify by text I want to identify by text here.
I want to mention that the location of the text where starts with <span></span> is a little bit weird. Specifically, i think that the text has whitespace and endline after the text, so I prefer to locate and click with input-title="I want to identify by text here">.
So far I tried:
driver.find_element_by_xpath("//*[contains(text(),'{}')]".format('I want to identify by text here'))
driver.find_element_by_xpath("//*[contains(text(),'I want to identify by text here')]")
but no luck.
Thanks in advance!
You just want to identify and click the input-title element? This should work, by text
driver.find_element_by_css_selector('div[input-title="I want to identify by text here"]').click()

Send Keys to Textarea title Seleium

I'm trying to send some text to the search textarea at Google Adwords Keyplanner tool using Selenium python.
When inputting manually the text from textarea goes to its attribute 'title'.
The textarea looks like this:
<textarea class="spl-a sprb-c spl-d" rows="1" id="gwt-debug-keywords-text-area" aria-labelledby="gwt-uid-94 gwt-uid-74" wrap="off" style="overflow: hidden;" dir="ltr" title="mytext"></textarea>
As a result:
driver.find_element_by_tag_name('textarea').send_keys('mytext')
or
driver.find_element_by_id('gwt-debug-keywords-text-area').send_keys('mytext')
produces
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
Is there another way to send keys to this search textarea? I have like 500 keywords which I need to grab data for.
full code of text area:
<div class="spl-c spI-d" style="width: 575px;">
<div id="gwt-uid-119" class="sprb-a">
<div class="sprb-b spl-b" style="display: none;" aria-hidden="true">For example, flowers or used cars</div>
<textarea id="gwt-debug-keywords-text-area" class="spl-a sprb-c spl-d" rows="1" aria-labelledby="gwt-uid-139 gwt-uid-119" style="overflow: hidden;" dir="ltr" title="my keyword" wrap="off"></textarea>
</div>
</div>
</div>
The element you are trying to interact with is but addressable by Selenium, because it is inside a div which is hidden - this one:
<div class="sprb-b spl-b" style="display: none;" ...
There is another element which is actually taking the user's input - look for elements with keypress event handlers, and also what changes in DOM web you enter characters.

Multi-select buttons in Selenium(Python)

As part of automation testing, I'm trying to figure out what is the best way to access a multi-select button in my company website. This button is not design in the popular way and it causes me problems using Select library. Here is how it looks like:
<div class="select-options options-overflow drop-select-link" style="position: absolute; top: 373px; left: 492px; width: 53px;">
<div class="drop-holder">
<div class="drop-list" style="height: 100px; overflow-x: hidden; overflow-y: auto;">
<ul>
<li class="jcfcalc" rel="0">
<a href="#">
<span>USD</span>
</a>
</li>
<li class="option-even jcfcalc" rel="1">
<a href="#">
<span>EUR</span>
</a>
</li>
</ul>
</div>
</div>
</div>
What you see here is a multi-select button which displayed different kind of currencies. I want to be able to choose currencies in a wise way - something like Select library. However, Select library doesn't fit to my code.
Is there a library that I'm not aware of? or would I have to do it with XPaths?
Select() couldn't be used with buttons. Any buttons! It could be used with select/option elements only!
In your case you can simply use link text to select required element (which is link, not the button) as
driver.find_element_by_link_text("EUR")
driver.find_element_by_link_text("USD")

Categories

Resources