How can I change the href text using javascript im stuck - html

i got stuck 4 hours ago and i cant figure this out, how can i make the balance to go from 0.13 to $50.13?
Here is the code:
<li class="notranslate" id="Mata" translate="no">
Balance: $0.13</li>
Im trying to do this using the console in google chrome

If you set an id on the link like this:
<a id="link" href="/wallet">Balance: $0.13</a>
Then you can use:
document.getElementById("link").innerHTML = "Balance: $50.13";
If you are not able to set an id then you can do:
document.querySelector("link[href='/wallet']").innerHTML = "Balance: $50.13";
The chrome inspect tool also has a feature where if you click the icon in the top-left of the tool, it will let you select an element from the page. After selecting an element, you can refer to it in the console as $0. So you after selecting the link you could do:
$0.innerHTML = "Balance: $50.13";

Since you do not have an id assigned to your a tag, you can use document.querySelectorAll, which will return a list of elements that match the specified selector.
Then, you can access each element using its index number, which in your case is 0, since you have only one element.
To change the text, simply use the text property:
document.querySelectorAll("a[href='/wallet']")[0].text = "Balance: $50.13";

Related

Rselenium and object with wbr

I am trying to use RSelenium to navigate with Firefox. I need to change an option button in about:config page for parameter browser.helperApps.neverAsk.saveToDisk. With RSelenium I am able to find the element I need to modify, but then I cannot find a way to update the value.
This is my HTML string to find
<tr class=""><th scope="row">browser.<wbr>helperApps.<wbr>neverAsk.<wbr>saveToDisk</th><td class="cell-value"><form id="form-edit"><input type="text"></form></td><td class="cell-edit"><button data-l10n-id="about-config-pref-save-button" class="primary button-save" title="Salva" form="form-edit"></button></td><td class="cell-reset"></td></tr>
I am using
go4 = rsc$findElement(using = "xpath", value = "//th[substring-after(normalize-space(string(.)),': ')=browser.helperApps.neverAsk.saveToDisk']")
but the error I get is
Summary: NoSuchElement
Detail: An element could not be located on the page using the given search parameters.```
How can I find the element and change the default value?
Thank you

using href or routerlink with #

I'm fairly new to changing paths / position of page so I would like a little help on this.
Say, when a button is clicked, I want to scroll down to another portion of the page. (where id of that section is 'xyz') however, I'm using an entirely different component to access that section.
If I were to use href, I can easily do : href="/app/appid#xyz"
however, if appid is a variable retrieved from the ts file, how can I insert it into my href?
It's easier to to use [routerlink]="['app', appid]" but how can I insert the "#xyz" into my string?
Or is there a completely separate and easier functionality I can use?
Thank you
Add the frament attribute:
<a [routerLink]="['app', appid] fragment="xyz">Link</a>
https://angular.io/api/router/RouterLink

Tracking Link Click on Google Tag Manager

I want to track clicks on the following button/link with Google Tag Manager. I created a trigger in Google Tag Manager that triggers when the element_id = 100. This works fine, except that when I click exactly on the text, it doesn't do anything, the link looks like a button, with the text in the middle of it. I can't change anything to the html or css, otherwise I can think of multiple things, so I need to find a solution without changing the html. Also, the 'myclass' class and the 'label' class get used in other elements.
<a class="myclass" id="100" href="http://www.url.com">
<span class="label">Text</span>
</a>
Anyone an idea?
Thanks a lot,
The following workaround worked:
Create trigger when element text contains "Text". This will trigger events on the button and the label on the button, of all buttons with "Text" as label.
Create tag for that trigger that checks with simple javascript if either the id of the current element = 100, which will happen when you click the button but not the label, or that the id of the parent = 100, which happens when you click the label. You can get the element that triggered the tag using the built-in variable "Click Element". Which you need to access the parent element.
Technically, you shouldn't have a CSS ID that starts with (or is) a number, so not sure if your code example is accurate or not. Whatever the case, you're probably better off using "matches CSS selector" so that you don't need to use any custom JS.
If indeed your HTML uses id="100", then the above will work. If it's anything else that doesn't start with a number, then you can use
#whatever > span

DOM Selector to get text of element ignoring children?

I'm using the Tab Modifier plugin for Chrome to dynamically rename some tabs that I use daily. In the tab Title definition, it says the following:
You can inject any DOM content with {selector}. Examples: {title} for website title, {h1}, {#id}, {.class}, etc.
Here is an example of the element I want to use to name the tab:
<td class="portalTitleInfoVal">
PORTALNAME
<a class="portalLink">Change Portal</a>
</td>
This is what I'm currently using for the title:
{.portalTitleInfoVal:nth-of-type(4)}
But, of course, the tab is named PORTALNAMEChange Portal.
How can I modify the DOM selector so that the tab is just named "PORTALNAME"?
I know I'm really late to the party, but I found this post while searching for an answer.
I'm working with a lot of old systems and all the tabs just says {title}, which is.. not useful when having 15-20 tabs open at once, and it's tedious to hard code every tab.
So.. I brute forced tested until I found a solution:
Every page has a breadcrumb:
<div class="breadcrumb noPrint">
Home "ยป"
Materials
123123
</div>
So they might have updated the extension since, but your guess was very close. I don't know why you were putting in 4, but I assume you had more elements than posted.
Anyhow, the way I got it to work were by:
{.breadcrumb :nth-last-child(2)} : {.breadcrumb :last-child}
So, there has to be a space between the .class and the child element, which in my case returns Materials : 12312
I haven't tried nearly half, but DoFactorys list of CSS selectors were a big help for me.
The element's first child node is the plain text, before the HTML element (<a>).
$('. portalTitleInfoVal')[0].childNodes[0].nodeValue
It looks like this plugin will only allow for CSS style element selectors compatible with querySelector. It then grabs the text from that element. From their github repo:
/**
* Returns the text related to the given CSS selector
* #param selector
* #returns {string}
*/
getTextBySelector = function (selector) {
var el = document.querySelector(selector), value = '';
if (el !== null) {
value = el.innerText || el.textContent;
}
return value.trim();
};

Python 2.7 Copy and paste hyperlinked text

I am using Python 2.7, Webdriver and Chrome. Manually, I can mouse swipe across text containing a hyperlink on a web page and copy it to the clipboard. How do I do this automatically? I have no issue finding the element containing the hyperlink. I am not trying to find the hyperlink. I am trying to paste it into a web page text box which does not process https://www.python.org/ ">Link within an "a" tag but processes it correctly when pasted from elsewhere i.e. "Link" with embedded href.
Even after OP clarifications, it's still hard to understand the exact issue, so I'll try to cover all possible options :)
Suppose we have an anchor element, like Link
We can find this element in such ways
element = driver.find_element_by_xpath('//a[text()="Link"]')
element = driver.find_element_by_xpath('//a[#href=" python.org "]')
depending on what information we currently know about the element and what exactly we want to scrap.
Also, we can use index of anchor element element = driver.find_elements_by_tag_name('a')[0]
1) To get value of href attribute:
value = element.get_attribute('href')
Output: https://python.org
2) To get value of text node:
value = element.text
Output: "Link"
3) To get complete HTML code of element:
value = element.get_attribute('outerHTML')
Output: Link