Puppeteer <a> tag click - c#

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.

Related

How to locate an Angular element in Selenium?

I have the following HTML
<div class="dx-filterbuilder-action-icon dx-icon-plus dx-filterbuilder-action" tabindex="0">
::before
</div>
I have tried locating this as follows in Selenium C#
driver.FindElement(By.XPath("//div[contains(#class, 'dx-filterbuilder-action-icon dx-icon-plus dx-filterbuilder-action']")
but the test is failing saying it could not Find Element. I'm trying to click the '+' element shown in the image below.
Not sure what I am doing wrong?
If the element is added dynamically, you need to wait until the element is in the dom.
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(3));
wait.Until(x=> x.FindElement(By.XPath("//div[contains(#class, 'dx-filterbuilder-action-icon dx-icon-plus dx-filterbuilder-action']"));
Instead of putting x.FindElement in the lamba, you can directly do a click. It basically repeats your action until it gets non-null non-exception response, or it timeouts. Giving time for DOM to update.

Unable to locate element in Sitecore 8.1 (selenium and c#)

I'm trying to run some automated tests in Sitecore 8.1 using Chrome and Selenium and c#. My code doesn't want to find any elements within the Sitecore pages, specifically the experience editor.
I am encountering the "unable to locate element" warning.
For eg: an item I want to .Click() is the toolbar ribbon button to expose the toolbar menu.
Here's the element:
<a data-sc-id="QuickRibbon" data-sc-click="trigger:button:toggleshow" data-sc-command="" data-sc-сontrolstaterequest="" data-sc-controlstateresult="" data-sc-postponedcall="" data-sc-ispressed="false" class="sc-quickbar-item sc-quickbar-button sc_QuickbarButton_53 data-sc-registered" title="Toggle the ribbon." data-sc-pagecodescriptfilename="" data-bind="ispressed: isPressed, visible: isVisible, click: click, command: command, enabled: isEnabled" data-sc-require="/-/speak/v1/ribbon/QuickbarButton.js" href="#" style="float:right"><img src="/sitecore/shell/client/Speak/Assets/img/Speak/Common/16x16/white/navigate_down.png" alt="Toggle the ribbon."></a>
Here's its XPath:
/html/body/div/div/div[1]/nav[1]/a[3]
I have extended the wait time to allow it to become visible as it can take a few seconds to load these pages. But this didn't work.
I have tried:
driver.FindElement(By.XPath("/html/body/div/div/div[1]/nav[1]/a[3]/img")).Click();
which gave me the "unable to locate" error
driver.findElement(By.className("class="sc-quickbar-item sc-quickbar-button sc_QuickbarButton_53 data-sc-registered"")).Click();
which gave me an error about unable to use compounded classnames.
I've tried a whole host of other options/combinations trying to pick up the alt text etc but I just can't get it to pick up the element.
Any ideas? Let me know if you need any more info.
Thanks
Change this line
driver.findElement(By.className("class="sc-quickbar-item sc-quickbar-button sc_QuickbarButton_53 data-sc-registered"")).Click();
to below line :-
driver.findElement(By.className("sc-quickbar-item sc-quickbar-button sc_QuickbarButton_53 data-sc-registered")).Click();
Edited 1..
If compound class does not work here you can perform action by using xpath as below :-
var wait = new WebDriverWait(driver, TimeSpan.FromMinutes(1));
var clickableElement = wait.Until(ExpectedConditions.ElementToBeClickable(By.xpath("//a[#data-sc-id='QuickRibbon']")));
clickableElement.Click();
Edited 2..
You need to switch frame before perform action if your element is present inside a frame as below :-
driver.SwitchTo().Frame("your frame name or id");
Hope it will work...:)
following suggestions from #Software_engineer I have managed to write this which works:
Thread.Sleep(6000);
driver.SwitchTo().Frame(driver.FindElement(By.Id("scWebEditRibbon")));
var wait = new WebDriverWait(driver, TimeSpan.FromMinutes(1));
var clickableElement = wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//a[#data-sc- id='QuickRibbon']")));
clickableElement.Click(); //click to drop down the toolbar
driver.SwitchTo().DefaultContent();
I needed to switch to the iframe!

How to click on all elements with the same class/parametr WatiN

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.
}
}

Google Custom Search Results - Link target blank does not go to new browser tab/window

I display the Google custom search results for my site onto a new page. I would like the each search result, when clicked, to go to a new browser tab/window.
From my understanding of Google GCSE, clicking on a result should automatically go to a new browser window. The Search Results linkTarget defaults to _blank. I added the explicit code anyways.
<div class="searchresults-only" data-linkTarget="_blank"></div>
<gcse:searchresults-only linkTarget="_blank"></gcse:searchresults-only>
What I see is that clicking on a search result stays in the same browser window and does not go to a new one.
What am I doing wrong?
<div class="searchresults-only" data-linkTarget="_blank"></div>
Div code is not neccessary for this task
try this code
<gcse:searchresults-only linkTarget="_parent"></gcse:searchresults-only>
it will help you.
just replace linkTarget="_blank" to linkTarget="_parent" and run it..

Click an HTML link inside a 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.

Categories