Start Google Chrome process and call GetElementByID - c#

I did Process.Start(CHROME) to run Google Chrome browser.
However, I need to get the emelemt ID so I can do click.
Example:
I launch Google Chrome, it will navigate to some URL I tell it, and it will get the elementId of the button and will click it
I don't have any code to show, because I don't know how to do it.

Related

C# - Get Url from browser

So just like uTorrent gets magnet links and opens them,
How can I setup my WinForm app to get a URL from Default Browser (in this case my default is Chrome) and open that URL in EO.WebBrowser within my app?
I don't have any code for this yet, as I don't know where to start.
Is this something that would be assigned as a Registry Key?
I know there are Registry keys for uTorrent to handle Magnet links in HKEY_CLASSES_ROOT\Magnet\shell\open\command.
What I have is WhatsApp Web open in EO.WebBrowser, and when I click on a URL starting with https://web.whatsapp.com or https://api.whatsapp.com it would open that link. The thing is the link should be changed to web.whatsapp.com, instead of api.whatsapp.com

C# Selenium Chrome clicking link from default chrome home page

I'm trying to get Selenium to click on one of the most visited web links from the default Chrome web page.
The problem is that Selenium cannot find the element on the page and I think it has to do with the fact that a web page technically didn't get loaded. When you open up Chrome it has HTML elements there but the address bar is completely empty. I think possibly this is why Selenium can't find the link? The code is simple and finding the XPATH wasn't an issue. I just don't know if this is a function that Selenium will be able to do or not. I'm trying to do the click because the navigate() function will not work when I put in the proxy information due to the fact that Selenium doesn't have a built-in way to handle a proxy with username and password.
At the end of the day I'm trying to get the username/password box to pop up by clicking on the link. When I open the browser with Selenium programmatically and then manually click on the link the username/password box pops up. But I can't get Selenium to find the element to click on programmatically.
var did = driver.FindElement(By.XPath("//*[#id='mv-tiles']/a[1]"));
did.Click();
UPDATE 1:
I was able to find the element when taking into consideration the iframe but clicking still is an issue.
var frm = driver.SwitchTo().Frame("mv-single");
var did = frm.FindElement(By.XPath("//*[#id='mv-tiles']/a[1]"));
//did.Click(); <-- I can see it go to the element but nothing occurs
IJavaScriptExecutor js2 = (IJavaScriptExecutor) driver;
js2.ExecuteScript("arguments[0].click();", did);
The JavaScriptExecuter is able to click the element but Chrome blocks the redirect with the following message:
[21040:24704:1204/150143.743:ERROR:CONSOLE(1)] "Unsafe JavaScript attempt to initiate navigation for frame with URL 'chrome-search://local-ntp/local-ntp.html' from frame with URL 'chrome-search://most-visited/single.html?title=Most%20visited&removeTooltip=Don%27t%20show%20on%20this%20page&enableCustomLinks=1&addLink=Add%20shortcut&addLinkTooltip=Add%20shortcut&editLinkTooltip=Edit%20shortcut'. The frame attempting navigation is targeting its top-level window, but is neither same-origin with its target nor has it received a user gesture. See https://www.chromestatus.com/features/5851021045661696.
", source: (1)
FINAL UPDATE:
I gave up and decided to do the browser extension solution for proxies with passwords: https://stackoverflow.com/a/35293222/5415162
That list of "Most Recent Pages" is actually in an iframe, which is probably why Selenium can't find it. Try updating the selector to account for the iframe, or maybe add a wait clause to allow the iframe to finish loading.
Regardless of that solution, I don't think it will act any differently than just navigating to the target URL. So to fix your root problem have you tried setting the proxy details when creating the ChromeOptions?

WebElement.click() causes page refresh

I have a <button> element. I call the click() function on this element using chrome webdriver.
appDone = driver.FindElement(By.Id(Constants.APP_DONE));
appDone.Click();
A strange thing happens in chrome, the page actually get reloaded. A pop up comes
"Are you sure you want to leave the page? You have unsaved data" Leave/Stay (buttons)
But same click event works fine in other browsers (Edge, IE, Edge). I opened the console in Chrome before clicking the button and placed debugger. Then executed the button click, the console window goes out a new console window comes up.
Anyone knows why this happens?
Things I have tried so far:
executed the button click using IJavaScriptExecutor
There is an beforeunload event in page, so when I pass onbeforeunload = null, I don't see the page refresh pop up anymore, but page still refreshes.
Tried to add type = button in the button, still no luck.
This screen works fine when run manually without Automation.
I have few logs recorded in server side, so when a page refresh happens, those logs are actually getting deleted, which should not happen.

C# - open browser to intranet on button click

I am aware
System.Diagnostics.Process.Start("https://www.facebook.com");
Goes to facebook but i want a button for a handy shortcut to the networks Intranet.
I obviously cant just put
System.Diagnostics.Process.Start("intranet");
Which is what i normally put in the browser, so how do i direct the button click here?
When you type "intranet" into the browser's address bar, the browser silently adds http://. When you copy the address from that address bar (after your intranet has loaded), you will get the full URL.
Try and use that in your Process.Start.

Selenium Chrome driver click does not work

IWebElement advancedSearchButton = driver.FindElement(By.Id("advanced-search"));
advancedSearchButton.Click();
this code works when the click button is displayed in the chrome driver, but when I resize the chrome to a very small size and the button is not displayed on the browser but it is loaded, click action does not work. When I minimize the chrome, click action works I am confused what to do ? I want to eventually try to make chrome as small as possible to hide the detail from the user kind of trying to run headless with windows C# please help thank you

Categories

Resources