How to check alignment of text using selenium RC - python

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']");

Related

How to get the value of href using text

I have the following text: 'abcdef' ,
I want to use this text to get the href. How can I do it?
<span class="thumb_link">
<a class="link_txt" href="/14803/tool/4554"> abcdef</a>
</span>
I tried the following but it failed
driver.find_element_by_css_selector('a[text()="abcdef"]')
Because the matching point is text, it must be obtained using text.
The link text would do that or if you have several similar link texts. Another way is with xpath.
driver.find_element_by_xpath("//a[text()='abcdef']").get_attribute("href")
Selenium's link text allows you to do that.
driver.find_element_by_link_text("abcdef").get_attribute("href")
will return the href.

How to add tags between tags in html using selenium web driver python

I want to insert a formatted text like bold in a text editor/text box on a website how would I do that?
I tried this :
browser.find_element_by_xpath("/html/body/div[4]/div/div/div[2]/div/div")
browser.execute_script("arguments[0].AdjacentHTML('beforebegin', arguments[1])", node, <'strong> bold </'strong>)
However, this seems to add adjacent to the HTML not inside the text box.
I would go with js method 'setAttribute':
browser.execute_script("arguments[0].setAttribute('style', arguments[1]);",node, "font-weight: bold");

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()

Selenium - Extract text in div without other tags (Python)

Trying to figure out how to access the text in the screenshot below without pulling all the span tags.
Doing element = driver.find_elements_by_id('response') gives me a list, but I can't seem to dig down further to access the text I want.
I also tried this after doing some searching:
element = driver.find_element_by_xpath("//div[#id='response']/pre")
But I get the same result.
Any tips?
element.get_attribute('innerHTML')
this will help you to get the text between two div tag
element.text
Should give out the contents of the element without any HTML tags.
In the case of the text being in the pure div the text is not extracted using element.text
Example:
<div>the text here</div>
I recommend to use a library called html2text and next:
html2text(element.get_attribute("outerHTML"))
It will do the trick!

Having trouble inputting into tinymce via selenium

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)

Categories

Resources