SeleniumLibrary Click button/link doesn't work - robotframework

Click Link href=http://www.tays.fi gives the error message:
"Link with locator 'href=http://www.tays.fi' not found."
But the item does exist on my page:
< a class="ot-landingpage__link" href="http://www.tays.fi" id="yui_patched_v3_11_0_1_1562143051415_173">www.tays.fi< / a >
What am I missing here? Any ideas, please?

The problem with your code is that href= is not a valid locator prefix.
Click link by default will search the id, name, and href of all anchor elements, so you can give the href without the prefix:
Click link http://www.tays.fi

Click Link expects a locator, not the href.
In your case
Click Link id=yui_patched_v3_11_0_1_1562143051415_173
OR
Click Link class=ot-landingpage__link
See documentation
http://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Click%20Link

Related

I am not getting to click on href link

I am trying to click on Href link but with no success.
This is the HTML of the page I am trying to click:
And here is the code that I tryed to use.
Welcome Page Should Be Open
Location Should Be ${WELCOME URL}
Title Should Be OrangeHRM
Click Link id=welcome
Wait Until Element Is Visible id=welcome-menu 8
#Click Link href=https://opensource-demo.orangehrmlive.com/index.php/auth/logout
Click Link xpath://a{test()='logout'}
I tried with "href" and "xpath", but both give the error:
No keyword with name XXXXXX found.
Can you please tell me what I am doing wrong?
The error is because you only have a single space between Click Link and the xpath. You need two or more spaces to separate a keyword from its arguments.
Also, xpath://a{test()='logout'} is not a valid xpath expression. You need to change the curly braces to square brackets, and change test to text. You also need to change logout to Logout.
xpath://a[text()='Logout']
For Click Link, you can also just specify the link text or href, for example:
Click Link Logout

How to write the Code for "Click on the Link" in Robot Frame Work?

When Click on the Declare Failure Link, using Click Link Code:
span[#id='ContentPlaceHolder1_grdFailureDetails_lblDtcCode_9']
the Error is Displaying as
Link with locator
'//span[#id='ContentPlaceHolder1_grdFailureDetails_lblDtcCode_9']' not
found.
Robot framework
Click link can only be used to click on link (e.g. an <a> element). If you need to click on a <span>, use Click Element.
Since the Click link keyword can break for other elements, I use the most generic way which is Click Element.
*** Setting ***
Library SeleniumLibrary
*** Test Cases ***
Example
Open Browser ${url} ${browser}
Click Element id:ContentPlaceHolder1_grdFailureDetails_lblDtcCode_9
Instead of Id, you may also use the xpath. In this case you will have:
Click Element xpath:.//span[#id='ContentPlaceHolder1_grdFailureDetails_lblDtcCode_9']
For more information, refer to https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html

Google Tag Manager tracking 404 page without unique URL

I'm trying to find a way to use Google tag manager to fire a tag only when a 404 page is reached. The problem is that the 404 pages do not have "404" in the URL because there is no redirect.
For instance, if you entered:
www.example.com/ofiwefoign
This is not a page on the website, and you see the 404 page telling you that the page could not be found. However, you aren't seeing www.example.com/404.
Since the URL could be anything, I need another way to get the tag to fire. I apologize if this question seems silly, but I'm having a hard time figuring it out.
I was wondering if I could possible track by H1 or title tag, which would include "404"
Thanks!
Yes, you can grab content from the page. Here is an example (looking at document.title):
Click on the tag to go to the Edit Tag screen.
On the right, under Firing Rules click on the + Add button.
Select Create new rule.
For Rule Name, name your rule something like "404 Page".
Under Conditions select "New macro..".
For Macro Name name the macro something like "404 title tag".
For Macro Type select "Custom Javascript".
In the Custom Javascript textarea, enter the following:
function () {
return (document.title.indexOf('404')!=-1)?'true':'false';
}
This will return a string value of "true" if the title tag contains "404", or "false" if not. You didn't specify what your title tag actually looks like, so you may need to adjust this to fit what you expect your title tag to contain.
Click Save to save the macro details, and you should now see {{404 title tag}} in the dropdown back on the previous screen where you are creating the rule.
Set the operator dropdown to equals and in the text field to the right, enter in "true" (no quotes).
Click Save to save the rule.
Click Save at the bottom of the Edit Tag page to save the tag settings.
On the top-right of the tag overview page, click Publish to publish the changes, and you should be good to go.

when i use link target _blank then onClick new tab open and suddenly tab again close

I search too much on Google but i couldn't find any result so i'm posting my question here
I'm using wordpress 3.6 and the wp e-commere plugin
i'm use this anchor tag
<a target="_blank" href="http://www.google.com">google</a>
i also use window.open(url,'_blank'); // function do same problem
when a user clicks on the link, a new tab opens and within 1 second it closes again.. its not working in mozilla and chrome, but it is working in IE
i checked and there is no theme problem.
if i add an anchor tag from e-commerce product then the tag target=_blank will not work, and if i add a anchor tag from wp product then the anchor tag will work...
How can i solve this problem?
and if i add href value with out http:// e.g
google
it opens in new tab successfully
but then its url is
localhost/wordpress/product/www.google.com
if i write a proper href with http://, so there is open and close issue.
Any one know it solution ?
i apply many type of jquery and javascript code, but actually when i write _blank, and then new tab opening then issue comes
Update:
i'm adding some javascript code,
i use this method to open new tab
function urltarget(url,target){
if (target == '') {
target = '_self';
}
window.open(url,target);
return false;
}
if i enter
<a href="" onclik="urltarget('http://www.example.com','_blank');" > Example </a>
//its work ok, but if i used .net url
<a href="" onclik="urltarget('http://www.example.net','_blank');" > Example </a>
//when .net comes in url then it create problem, new tab open and again close.
but it work in IE

Selenium WebDriver - how to verify multiple lines text

I have an html page with following contents:
<center>
This is Login page.
<br>
Please click below link to Login.
<br>
Login
</center>
How can I verify all the static text above using one webdriver command?
I tried these but none of it works :(
driver.findElement(By.xpath("//*[contains(.,'This is Login page.<br>Please click below link to Login')]"))
driver.findElement(By.xpath("//*[contains(.,'This is Login page.\nPlease click below link to Login')]"))
Anyone know how to do it?
You can do:
webDriver.findElement(By.id("<ID of center tag>")).getText().contains("This is Login page.Please click below link to Login.Login");
Feel free to use a locator of your choice instead of By.id.
Basically getText() of any WebElement returns the textual content of the node, stripped of all the HTML tags and comments.
This is more a limitation of XPath than Selenium.
I do not see why you are using the global XPath selector there, a better XPath selector would be:
By.XPath("//center");
If it's the only "center" tag on the page, or even:
By.XPath("//center[contains(text(), 'This is a Login page'")
The /r and /n characters will be retained if you do it through code instead of blindly searching for it in XPath.
How to find the texts if the texts has space inbetween them.
<br>
<br/>
Please click below link to Login.
<br>
Login
</center>
You can do with "\n"
return getText(supportText).contains("Information:" + "\n" +
"This page is for use by the TECHNICAL TEAM only. Following links will be active, only if you have access (subscription) to those modules.");

Resources