Set href string in angular 8 given by server - angular8

I have this in my html:
<a href="{{cookie_policy_url}}" target="_blank" class="primary">
where cookie_policy_url is a string that is initially blank and that I get from the server, this way:
this.navService.getUrlCookiePolicy().subscribe(s => {
this.cookie_policy_url = s;
this.changeDetector.detectChanges();
});
The string I receive is correct, but for some reasons it doesn't update the href url, so when I click it it is empty. What is the correct way to use this?

Related

How to replace some text with URL in vue?

I want to replace some text from the string with link. I dont know how can I display it. SO far below code displays string with href link.
<span class="text">{{ $t(myText) }}</span>
myText() {
var text = "You can click text.";
var href = "<a href='https://www.google.com'>Click Here</a>";
var replaced = text.replace("click", href);
return replaced;
},
To elaborate on my comment: the handlebars/moustache syntax is used to insert plain text into your template. That means that any string that contains HTML will be inserted as-is without parsing it as DOM.
In order to insert HTML into your template, you will need to use the v-html directive, i.e.:
<span class="text" v-html="$t(myText)"></span>
However, note that this presents a security risk if you're allowing users to insert their own content into the element.

Need Help in programming using selenium

I have a problem is I can not store the value of href on the page
<a target="_blank" href="http://xxx.xx/RLS?mid=-1050286007&guid=53v90152oyA8bDg&lid=26527875" clinkid="26527875"></a>
How can I take the value of href using findElement ?
You should try using getAttribute after finding element as below :-
String href = driver.findElement(By.cssSelector("a[clinkid = '26527875']")).getAttribute("href");
Edited 1:- if clinkid dynamically generated try using by visible link text as below :-
String href = driver.findElement(By.linkText("your link text")).getAttribute("href");
or
String href = driver.findElement(By.partialLinkText("your link text")).getAttribute("href");
or
String href = driver.findElement(By.cssSelector("a[target = '_blank']")).getAttribute("href");
Edited 2 :- if you want query string from url, you should implement java.net.URL to parse it into url and then use getQuery() to get query string as below :-
URL url = new URL(href);
String queryStr = url.getQuery();
Hope it helps..:)

Testing relative positions of elements

On the page under test I have the following Support link:
Which is represented with the following HTML:
<div class="ap-version-panel ap-version-support">
<i class="fa fa-external-link"></i>Support
</div>
What I'm trying to is to test that the icon is located before the "Support" text. How can I do that?
I've tried the following - locate the icon element with an XPath that additionally checks that there is "Support" text after and check if the element is present:
expect(element(by.xpath("//text()[. = 'Support']/preceding-sibling::i[contains(#class, 'fa-external-link')]")).isPresent().toBe(true);
This works but it is quite ugly and I don't like that the actual position check is hidden inside the XPath expression which is not really readable and reliable.
I recommend changing the product under test by adding a <span> and move the text "Support" into the <span>.
<div class="ap-version-panel ap-version-support">
<i class="fa fa-external-link"></i><span>Support<span>
</div>
But if you cannot change the product, you can use javascriptExecutor to get childNodes then check order of the nodes:
var aFunctionToCheckOrder = function (arguments) {
var nodes = arguments[0].childNodes;
var result;
// Check nodes[0] = <i>
// Check node [1] is textNode and its value = "Support"
return result;
}
var supportLink = element(by.linkText("Support"));
browser.executeScript(aFunctionToCheckOrder, supportLink).then(...)
As you can see, it is more uglier than your solution. You'd better change your product under test.

how remove tag html when show text(froala editor)

iam use editor froala when insert text then show text iam see tag html in text
plese see text
<B><p class="fr-tag">test
testttt good<br></p></B>
iam use this code for show and remove tag
<dd>
#{
#Html.DisplayFor(model => model.FTxtnews)
}
</dd>
var val = $('textarea').val();
val = val.replace("</p><p class="fr-tag">", '<p class="clear">');
edit:
iam sloved this problem with use #Html.Raw
try assigning your HTML string to an element and get text of it by removing all child elements like this,
var dummyString = '<B><p class="fr-tag">test testttt good<br></p></B>';
$('#dummyDiv').html(dummyString);
var val = $("#dummyDiv")
.clone() //clone the element
.children() //select all the children
.remove() //remove all the children
.end() //again go back to selected element
.text();
Have a DIV in your page (possibly hide it) with id 'dummyDiv'.
Hope it works. Thank you.

How can you get an attribute using Selenium 2 and PHPUnit?

I'm trying to follow the URL of a hidden Log Out link. The HTML looks like this:
<li id="wp-admin-bar-logout"><a class="ab-item" href="http://www.ananda.org/wp-login.php?action=logout&_wpnonce=f633c2d0a4">Log Out</a> </li>
Getting the element is straightforward:
$link = $this->byXPath( '//*[#id="wp-admin-bar-logout"]/a' );
Can I get attributes?
You can get attributes of elements, apparently, though I couldn't find this documented anywhere.
Here's the complete solution I used:
protected function doLogout() {
$this->url('/wp-admin');
$link = $this->byXPath( '//*[#id="wp-admin-bar-logout"]/a' );
$this->url( $link->attribute('href') );
}