Click at link by address template - html

I'm using Selenium for making some work: script should click at link followed by it's own address. For example, there is a method: clickAndWait. I have to pass it link title. But at my page this title changes, so I have to pass address to click at.
Could you help me with this?
p.s. I asked this question in selenium group, but still have no answer.
upd: For exampe, I have such html-code:
Some changeable title
Some changeable title
And selenium pseudocode:
ClickAndWait('Some changeable title')
But I have to click at site 'another.com', not 'lalala.com'. And link's title changes every time. Only link address is the same.

You could use one of the following locators:
//use XPath to match links with full href value
selenium.clickAndWait("//a[#href='another.com']");
//use XPath to match links with href values that start with string
selenium.clickAndWait("//a[starts-with(#href,'another.com')]"); //use partial href value
//use XPath to match links with href values that contain string
selenium.clickAndWait("//a[contains(#href,'another.com')]"); //use partial href value

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

Using a tag in a dynamic url

I'm struggling to get the contact ref to work from different pages.
Basically for every product a different detail reference is provided (see 4867820 below).
I would like to create a button which links to the #contact id for every page on the website.
Basically if I put a link on the button including the reference, this works perfectly.
http://www.mywebsite/product/4867820#contact
However I am wondering if I can create something similar where the button links to the contact id on the same page without using the reference number.
http://www.mywebsite/product/this page#contact
So basically my question is how do I link to only #contact on this page without the reference numbers, so I can create 1 button on the page template.
Regards,
Assuming it will always point to the same page as the button:
a) If you are able to use anchor tags instead of buttons (and CSS-style them to look like buttons), you can simply point the anchor's href attribute to the section name.
It works like a relative link, just appending the href to current URL. Like so:
Contact Here
Or b) if you have to use only a <button> or <input> element specifically, you will need to use javascript to set the location in onclick handler of the button. For details on that see: Javascript inline onclick goto local anchor

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

How can I pass a value when creating a new tab panel with CSJS

I want to create a new tabbed panel for the Dojo tab container using CSJS like:
dijit.byId('#{id:djTabContainer1}').createTab({ tabTitle: Math.random()});
The default tab panel has an panel that will use the iframe tag and I want to pass in the above call the src html attribute to the panel.
Question : I can specify a url to load in the iframe. Is there a way to pass this?
It seems like the createTab only does certain tab related parameters like action and tabTitle.
Howard
The syntax is somewhat obscure here. Starting with the code in the ExtLib demo app:
XPagesExt.nsf/Core_DynamicTabs.xsp
Change the script in button4 to:
dijit.byId('#{id:djTabContainer1}')
.createTab({
"newName":'Tab'+Math.random(),
"newHref":'/XPagesExt.nsf/page5.xsp'})
to match the syntax you're requesting.
And, in the tab that's referenced by defaultTabContent, change the title and href to use those passed URL parameters:
<xe:djTabPane xp:key="doc" id="djTabPane2"
title="${javascript:/*load-time-compute*/param.newName}"
href="${javascript:/*load-time-compute*/param.newHref}"
It will create the tab and will attempt to load the href contents. I'm not seeing it as an iframe though - it's just a container div.