In Robot Framework, I am trying to check whether "XXX" exists in the source code as follows:
<button class='btn-aaa'>
<span class='bbb'>
XXX
</button>
I tried with the following codes but they failed:
Page Should Contain Element | //button/span/following-sibling::text()="XXX"
---> Valid xpath but encountering error in Robot Framework with error message "InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression //button/span/following-sibling::text()="XXX" because of the following error: TypeError: Failed to execute 'evaluate' on 'Document': The result is not a node set, and therefore cannot be converted to the desired type."
Page Should Contain Element | //button/span[#class='bbb']/following-sibling::contains(text(),"XXX")
---> Invalid xpath
Page Should Contain Element | //button/span[#class='bbb']/following-sibling::[contains(text(),"XXX")]
---> Invalid xpath
Could anyone please suggest the proper way to check for "XXX" using the right xpath in Robot Framework?
The following are the info of the tools utilised:
robot framework version 3.0.4
Selenium Version 3.14.1
Selenium2Library Version 3.0.0
Python 3.6.6
Edited:
I really appreciate that all of you are trying to help. Thank you very much.
I will try to provide as much info as I can, so that you can help me as well.
I tried with:
//button[normalize-space()='View Data']
Unfortunately, it found nothing.
There are other buttons but there is only one with the text "View Data".
Here are more detailed code. I don't know whether it will help comparing with the simplified one mentioned earlier:
<button class="btn btn-submit float-left" type="button" onclick="return doActionParam('https://www.blabla.com/blabla',{op:'viewBla',blaId:'wxyz', activeTab:getActiveTabName()})">
<!--groupParent.-->
<span class="bongobongo"></span>
View Data
<button>
Hope the info is more helpful this time. Thanks again.
Additional Info:
Browser: Mozilla Firefox 62.0.3 (64 bits)
Could you try this xpath: //button[normalize-space()='XXX']
Your test should be: Page Should Contain Element //button[normalize-space()='XXX']
The problem is that your page does not contain a span with the text "XXX". What it actually has is "newline, XXX, newline". Also, neither the span nor the button has a sibling (and thus, no following-sibling).
You can ignore the whitespace surrounding the text with normalize-space. For example, the following works for me when I create an HTML document identical to what you have in your question:
Page should contain element //button[normalize-space()='XXX']
This should work on the updated example in your code, by simply replacing XXX with View Data:
Page should contain element //button[normalize-space()='View Data']
Related
I have this piece of HTML and I'm trying to select the <a href> link using xpath.
<li class="footable-page-nav" data-page="next" aria-label="next"><a class="footable-page-link xh-highlight" href="#">›</a></li>
I need the selector to be reasonably specific since "footable-page-link" exists in multiple places in the HTML.
I've tried this:
//li[#class='footable-page-nav']/a[#class='xh-highlight']//#href
Selenium throws an error: selenium.common.exceptions.NoSuchElementException
If I shorten the xpath expression to //li[#class='footable-page-nav'] just to see if I'm on the right track then I get
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable: element has zero size
What am I missing?
Try changing your xpath expression to
//li[#class='footable-page-nav']/a[contains(#class,'xh-highlight')]//#href
and see if it works.
Hi I have this element from a dropdown menu I try to select:
<div class="tt-suggestion tt-selectable">
<strong class="tt-highlight">Auto Customer</strong>
</div>
If I use element(by.xpath("//strong[contains(text(),'Auto Customer')]")).click(); I can select it no problem. But if I use element(by.xpath("//*[contains(text(),'Auto Customer')]")).click(); I get "Failed: element not visible"
Can someone explain this to me please?
Thank you
Because the * in //*[contains(text(),'Auto Customer')] means any tag, not only the strong Tag. But //strong[contains(text(),'Auto Customer')] must be strong Tag.
//*[contains(text(),'Auto Customer')] should find more then one elements on page, and the first one is not visible. You can try this xpath in Chrome DevTool's Element Tab to see how many elements it can find and the first one is visible or not.
I have the following HTML:
<input type="submit" style="-webkit-user-select:none;line-height:100%;height:30px" value="Advanced Search" class="jfk-button jfk-button-action adv-button">
I have written xpath as: //input[#value='Advanced Search']
What is the CSS locator/path?
It's difficult to answer as optimum search selectors need the entire source code to be written, as several DOM Elements in the document could be returned for a generic selector.
In this case, a more detailed selector would be :
input.adv-button[value='Advanced Search']
You can convert your xpath into corresponding CSS Locator by using the following website:
http://cssify.appspot.com/
For example:
Go to site http://cssify.appspot.com/
Insert the XPath //input[#value='Advanced Search'] into text field
Click submit button and observe the result
You can see the corresponding CSS Locator as follows:
input[value="Advanced Search"]
Selenium Webdriver. Looking to Locate New Article from following code. Please note this is under an iframe.
<img class="rtbIcon" src="/icons/16/app/shadow/document_add.png" alt="">
<span class="rtbText">New Article</span>
I have tried to locate with xpath and many other ways. But following is what I get everytime
Code : driver.findElement(By.xpath("id('RadToolBar1'):div:div:div:ul:li[3]:a:span:span:span:span"));
Result:
The given selector id('RadToolBar1'):div:div:div:ul:li[3]:a:span:span:span:span is either invalid or does not result in a WebElement. The following error occurred:
New article has no name, id so please if some one can help find me solution.
Your xpath seems to be wrong. The best way to get the xpath for any element on a page is by installing mozilla add on - Fire Bug. You can inspect any element using this add on and also copy the correct xpath of your element present on the page.
This should be your xpath -
driver.findElement(By.xpath("//*[#class='rtbText']"));
or
driver.findElement(By.linkText("New Article"));
One of these should work. Let me know if you face any problem.
I have got following html
<a disabled="disabled"><img alt="First" src="/Content/Images/Grid/disabledFirst.png"></a>
And I run following expect on this html
expect($(element)).toBeDisabled()
where element is the selector for above html. The expect fails. Further investigation lead to following code in jasmine-jquery-1.3.1.js
toBeDisabled: function(selector){
return this.actual.is(':disabled');
},
which for some reason is returning false. I'm sure I'm missing something very basic here but just not able to spot it.
This fiddle shows that jQuery only finds inputs not anchors when using :disabled. It's understandable because the anchor element doesn't have the disabled property