I would like to get a node's text without also getting its children's text. E.g. how do I get the text "hello" from the following HTML?
<div id="myid">hello <b>world</b></div>
The only way I've been able to make this work is by using reflection to bypass the WebElement's visibility protection:
WebElement webElement = driver.findElementById("myid");
Method getter = webElement.getClass().getDeclaredMethod("getElement");
getter.setAccessible(true);
HtmlElement htmlElement = (HtmlElement) getter.invoke(webElement);
String name = htmlElement.getFirstChild().getTextContent();
Try the XPath-expression
//div[#id='myid']/text()
for all text nodes directly under that div, and
//div[#id='myid']/text()[k]
for the k-th text node under that div.
I have tested this XPaths with XSL using libxslt, but not in the webdriver (but I know webdriver supports XPath).
Related
I want to get the value of the attibute of an image like 'src'. also the image have a classname, i select the image using the class name, but how can i get the attribute?
<img src="http://somelink.jpg" class="img-fluid">
here's how i use the xpath selector to select an image using the classname
//img[#class="img-fluid"]
how can i get the value of an attr of an image "src"?
so i'll have the link "http://somelink.jpg"?
You can use the below xpath to get the src value.
//img[#class="img-fluid"]/#src
For example, you can get src attribute of all avatar images in this page using the below xpath.
//*[contains(#class, "user-gravatar")]//img/#src
You may also take a look at this xpath cheatsheet.
I have an Iframe with a P tag in it. That P tag is where you can write a text using the keyboard. But using 'Input Text' seems not to work in in since Input text does not identify P tag as a text input field. Did anybody happened to experience the same situation?
Ive tried reading similar post but it seems to be irrelevant to my issue.
Enter Message
element should be visible id=cke_mail-editor-template-add
select frame xpath=//*[#id="cke_1_contents"]/iframe
wait until element is visible xpath=/html/body/p[1]
input text xpath=/html/body/p[1]
... Test message
Below is the Element:
/html[1]/body[#class="cke_editable cke_editable_themed cke_contents_ltr pastable pastable-focus"]/p[1]
Expected Result: should be able to enter text
Actual Result: ElementNotInteractableException: Message: element not
interactable
Trying to check if the element set focus to using class header matching by text and getting error unable to locate the element. I know the header title which is 'My Details' in this example, and using this title, how to locate the element?
<div class="attribute-group-header card__header">
<h3 class="attribute-group-title card__header-title">My Details</h3>
</div>
Element should be focused //div[contains(.,'My Details')
To locate the h3 in your example code, use this xpath //h3[contains(text(),'My Details')]
To locate the div which has card__header in class, use this xpath //div[contains(#class,'card__header')]
It worked fine with this keyword and the X-path reference. Thank you all for guiding me to find the solution
Element should be enabled //h3[contains(text(),'${MyLinkText}')]
I have a pdf image inside the anchor tag.I need to get the element and with that I need to click on the pdf link. Tried with element by Id but getting element not visible but it is visible.Kindly help in getting the element through css,struck in this for nearly 2 days.
<div class="az content-block">
<ol>
<li>{{'check.ant.label'|text}}</li>
<li>{{'check.bed.label'|text}}</li>
<li>{{'check.hin.label'|text}}<a id="checkPdfLink" ng-href="{{check.pdf}}" target="_blank"><span class="az icon-pdf"></span></a></li>
</ol>
</div>
Did you try with css Selector? If it is hard to find a unique ID, try right click on the inspect element of the pdf link and click on Copy Unique Selector and try to click on it.
element(by.css('paste your Unique Selector here')).click();
Hope this helps. :)
In a simple case, this is just:
element(by.id("checkPdfLink")).click();
But, since you are getting the "Element not visible" error, there could be several reasons for that. One, is that you may need to actually do something to make the element visible - open up a menu, or a dropdown. The other reason, could be the timing problem. Wait for the link to become clickable before clicking:
var EC = protractor.ExpectedConditions;
var pdfLink = element(by.id("checkPdfLink"));
browser.wait(EC.elementToBeClickable(pdfLink), 5000); // wait up to 5 seconds
pdfLink.click();
Can anyone tell me if it's possible to have a the text in a single label control displayed in more than one style.
e.g. I have a label
I want the the text to appear with the style "english" (which it does), but I want the "th" of the text to be different (bold, different colour, whatever).
So, the question in a nutshell is: Is there a flex equivalent of the following HTML?
<p class="english">bro<span class="highlight">th</span>er</p>
If not, can anyone think of a good workaround, short of having to separate the text into multiple label controls (thus making alignment a bit of a nightmare)?
Thanks to anyone who can help!
Dan
yes, try the following
var la : Label;
la.htmlText = '<TEXTFORMAT LEADING="3"><P ALIGN="LEFT"><FONT FACE="Arial" SIZE="14" COLOR="#000000" LETTERSPACING="0" KERNING="1">what ever texst you wish</FONT><FONT FACE="Verdana"SIZE="18" COLOR="#848484" LETTERSPACING="0" KERNING="1">more text here</FONT></P></TEXTFORMAT>';
Yes, it's possible. Take a look at the Label.htmlText documentation in the livedocs which explains how to set markup on a Label control, e.g.
<mx:Label>
<mx:htmlText><![CDATA[This is an example of <b>bold</b> markup]]></mx:htmlText>
<mx:Label/>
The Text.htmlText reference has a full list of the tags supported and gives detail about the Paragraph and Span tags :
Paragraph tag
The <p> tag creates a new paragraph.
The text field must be set to be a multiline text field to use this tag.
The <p> tag supports the following attributes:
align: Specifies alignment of text within the paragraph; valid values are left, right, justify, and center.
class: Specifies a CSS style class defined by a flash.text.StyleSheet object.
Span tag
The <span> tag is available only for use with CSS text styles.
It supports the following attribute:
class: Specifies a CSS style class defined by a flash.text.StyleSheet object.
Ultimately, there are quite a few ways to do what you want.