Handle drop down on web page dialog selenium C# - c#

I am working on a automation of a website using selenium and C# , but i stuck in a situation where on a button click a new webpage dialog open and on that web page dialog we have to select some value and click on save button. Problem is i am unable to switch to that webpage dialog and even f12 window not working on that webpage dialog this website is only working on IE so no other option . Please help me. Here is post screenshot of webpage dialog and HTML code of Button which open that dialog box.

I have got this problem, where the title of page is Webpage dialog same as you. In this window you can not inspect the element. Solution to this is go to
Internet Explorer-->
Internet Options -->
Security tab -->
Custom Level -->
Disable the option : Allow Websites to open windows without address or status bar
Now, You can inspect element by F12 in IE. now, simply write all the selenium commands, you can also use JavaScriptExecutor for that, If you dialog box calls JavaScript.

Related

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?

How to type in a field and click a button on a site that I navigated to

I was able to navigate to my desired site using the following code
System.Diagnostics.Process.Start("https://www.google.com/");
How can I provide an input from a variable that I declared in CodeBehind? After that, I am planning to click the button and then further use the data.
Basically, my problem is about controlling the elements that are found in the site that I navigated to using C#.
Thank you very much!
Use Selenium. You can download the NuGet package from here. Below is some code which goes to gmail and then finds the email textbox and types some text into in. It then presses a button.
Driver.Navigate().GoToUrl("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1");
Driver.FindElement(By.Id("Email")).SendKeys("myEmail"); // Type email
Driver.FindElement(By.Id("next")).Click(); // Click the button
Driver.FindElement(By.Id("Passwd")).SendKeys("myPass");
Also download the chromedriver from here and put the .exe file in your bin folder. Selenium will pick it from there and use it. You can use any web driver.
EDIT
To open a new tab:
IWebElement body = driver.FindElement(By.TagName("body"));
body.SendKeys(Keys.Control + "t");

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

Browser back button does not work with asp controls

I have a site with few asp:CheckBoxList and asp:DropDownList controls. Checking few options or selecting few items in the dropdowns makes the back button browse to same page just with previous selections. I would like the back button on the browser take the user to the previous website visited. As example: if the last visited site was: default.aspx, then the back button from my current site should go back to default.aspx.
Adding few header options regarding caching only broke the back button to: Page Not Found message.
How can the user browse back to the default.aspx by the first back button clicked on the browser?
Just need to confirm, are u using IE 10 to run the web system?
I had encounter asp control component not working properly when i was using IE 10.
Maybe consider using other browser type like firefox and safari to see if it can work properly

selenium fails to open intended new window

I am trying to automate web based application (asp.net) through selenium web driver.
Web application has login page and once I log in, I need to click on a button that opens a new window and then perform operations on this new window. So far, my code is able to login and click the button. Two problems here:
instead of opening desired window on click, it opens the login page
this login page is opened in the same window, not new one
I have used below statement to switch to new window:
webDriver.SwitchTo().Window("newwindowname");
Have you tried to use the window handle?
Get the window handles
ReadOnlyCollection<string> handles = webDriver.getWindowHandles();
String myWindowHandle = handles.LastOrDefault();
And use the last one in the swtichTo statement
webDriver.switchTo().window(myWindowHandle );

Categories

Resources