I using WatiN dll, i have a table and in each td i have link with <a> href =javascript:void(0) </a> ,i my case i have same href in all of them(they dont have class),i need to click on them all (they open new tr with data) ,and then save the html page,my problem to click on all of them , i can click on the first one like this
Frame frameBODY = browser.Frame(Find.ByName("BODY"));
frameBODY.Link(Find.By("href", "javascript:void(0)")).Click();
But i need to click on all links that have "href", "javascript:void(0)",i think i need you use ListCollection but i new in WatiN and still cant find the way to do this.
Any ideas how click on all links with "href", "javascript:void(0)".
You can get all the links inside of frame body as below.
Frame frameBODY = browser.Frame(Find.ByName("BODY"));
LinkCollection links = frameBODY.Link;
foreach(Link link in links)
{
if(link.GetAttributeValue("href").Contains("javascript:void(0)"))
{
link.Click();
// TODO - Add logic here for saving the file.
}
}
Related
First of all, good work everyone. I'm pulling data from a site using Puppeteer, after the data extraction process is finished, I want to move on to the next page. For this, there is an tag as below.
<a class="paginate_button next" aria-controls="empTable" data-dt-idx="7" tabindex="0" id="empTable_next">Next</a>
The codes I'm trying to click are as follows
WaitUntilNavigation[] waitUntilNavigations = new WaitUntilNavigation[1]; waitUntilNavigations[0] = WaitUntilNavigation.DOMContentLoaded; await page.GoToAsync(url,new NavigationOptions { WaitUntil = waitUntilNavigations });
await page.ClickAsync("a#empTable_next");
I'm sure I'm on the right page but I'm getting the following error.
PuppeteerSharp.SelectorException: No node found for selector:
a#empTable_next
I need your help.
I have an array of some URL links. And I need to open all theese links by clicking one HyperLink, located in cell of Telerik GridHyperLinkColumn.
Is there any method to do this?
Now I have a code which sets first way to my HyperLink:
HyperLink link = (HyperLink) item["documents"].Controls[0];
if (link.NavigateUrl.Contains(";"))
{
string[] linktext = link.NavigateUrl.Split(';');
link.NavigateUrl = linktext[0];
}
I would probably take a quick look at this SO answer here.
The takeaway is that this is not possible without using JavaScript functions:
Without JavaScript, it's not possible to open two pages by clicking
one link unless both pages are framed on the one page that opens from
clicking the link. With JS it's trivial.
The example is this:
<p><a href="#" onclick="window.open('http://google.com');
window.open('http://yahoo.com');">Click to open Google and Yahoo</a></p>
This would also work: (again see answer here)
Open Two Links With One Click
I'm working on a school project in Visual studio 2010.
I'm trying to make a page with many image-thumbs. When I click one of these thumbs I want them to appear in fancybox. The thing is, the client is supposed to be able to upload more images. So I figured I'd let my javascript print the thumbs and images with an array.
This is the Javascript that loads the images in an <a>:
var divbilder;
var bildenavn = ["img/Media/3.jpg", "img/Media/4.jpg"];
var bildethumb = ["<img src='img/Media/3_thumb.jpg' alt='' />", "<img src='img/Media/4_thumb.jpg' alt='' />"];
window.onload = init;
function init() {
divBilder = document.getElementById("divBilder");
genererBilder();
}
function genererBilder() {
for (var i = 0; i < bildenavn.length; i++) {
var nyttBilde = document.createElement("a");
nyttBilde.className = "grouped_elements";
nyttBilde.rel="group1";
nyttBilde.href = bildenavn[i];
nyttBilde.innerHTML = bildethumb[i];
divBilder.appendChild(nyttBilde);
}
}
So far so good, the images are loaded perfectly into my site.
But they wont appear in fancyBox when I click them, I get the image in a blank page.
Here is my code for FancyBox:
$(document).ready(function () {
$("a.grouped_elements").fancybox();
});
However, I did try to put this code:
<a class="grouped_elements" rel="group1" href="img/Media/3.jpg"><img src="img/Media/3_thumb.jpg" alt=""/></a>
into my html. Then the fancybox works perfectly.
In other words, i have all the fancyBox files needed in the head-tag and so on.
Other notes you might need: When i "inspect element" in Chrome, my javascript has made codelines that is identical to the one I manually put in my html. With different href and src inside the <a> of course.
I am using ASP.net c# with MasterPage.
Any help at all appreciated, I'm kinda new to Jquery and javascript so be kind :)
The only reason I can think this is happening is because you are using fancybox v1.3.x.
If the above is correct, fancybox v1.3.x doesn't support dynamic added elements and this why your hard-coded link works only but not those generated by your js.
I wrote a workaround using jQuery .on() method that you can find here
You may need to tweak the code to match your own structure like
$("#divBilder").on("focusin", function(){ ....
I have a web browser control, already navigated to a page. Now I want to search for a specific text in the page, and scroll to the first occurrence.
Being able to scroll to other occurrences is a bonus.
You can try this code:
webBrowser1.Select();
SendKeys.Send("^f");
I don't know if it works in a WebBroswer. We make the broswer(IE/FF/etc) window scroll to some text with the following code:
//source code of http://www.sample.com/sample.html
<html>
...
<span name="aim">KeyWord</span>
...
</html>
If I want the window to scroll to the "KeyWord", simply visit http://www.sample.com/sample.html#aim
Using string document = myWebBrowser.DocumentText to get the source code of the page, and search the text in the string, get its node name, and navigate it using #.
See this if it helps:
string PageSource = null;
PageSource = WebBrowser1.Document.Body.InnerHtml();
if (Strings.InStr(PageSource, stringtoFind) > 0) {
...insert an Anchor tag here and then use
WebBrowser1.Navigate to go to the the new URL with the #Anchor tag
} else {
...whatever else
}
One way...
Use the Ctrl + F Key to invoke Find, native to the WebBrowser Control?
C# Visual Studio 2010
I am loading a complex html page into a webbrowser control. But, I don't have the ability to modify the webpage. I want to click a link on the page automatically from the windows form. But, the ID appears to be randomly generated each time the page is loaded (so I believe referencing the ID will not work).
This is the content of the a href link:
<a
id="u_lp_id_58547"
href="javascript:void(0)"
class="SGLeftPanelText" onclick="setStoreParams('cases;212', 212); window.leftpanel.onClick('cases_ss_733');return false; ">
My Assigned</a>
Is the anyway to click the link from C#?
Thanks!
UPDATE:
I feel like this is close but it is just not working:
HtmlElementCollection links = helpdeskWebBrowser.Document.Window.Frames["main_pending_events_frame"].Document.GetElementsByTagName("a");
MessageBox.Show(links.Count.ToString());
I have tried plugging in every single frame name and tried both "a" and "A" in the TagName field but just have not had any luck. I can just not find any links; the message box is always 0. What am I missing?
Something like this should work:
HtmlElement link = webBrowser.Document.GetElementByID("u_lp_id_58547")
link.InvokeMember("Click")
EDIT:
Since the IDs are generated randomly, another option may be to identify the links by their InnerText; along these lines.
HtmlElementCollection links = webBrowser.Document.GetElementsByTagName("A");
foreach (HtmlElement link in links)
{
if (link.InnerText.Equals("My Assigned"))
link.InvokeMember("Click");
}
UPDATE:
You can get the links within an IFrame using:
webBrowser.Document.Window.Frames["MyIFrame"].Document.GetElementsByTagName("A");
Perhaps you will have to isolate the link ID value using more of the surrounding HTML context as a "target" and then extract the new random ID.
In the past I have used the "HtmlAgilityPack" to easily parse "screen-scraped" HTML to isolate areas of interest within a page - this library seems to be easy to use and reliable.