I want to access some data which is copied to the clipboard on a website when you click a button (Jscript)
I use Remotewebdriver (ChromeDriver) to control the testcase but couldn't find out how to access this information.
Anybody knows how?
If possible with c# but a java solution may also work.
Thx
So I could not figure out how to do this so my way was to render a textarea with Jquery and CTRL+V the text into that box just to then get the value back with webdriver. Not pretty but it works
var javaScript = "$( \".d-modal-footer\").html('<div><textarea id=errormessagecopy maxlength=\"5000\" cols=\"80\" rows=\"40\"></textarea></div>');";
WebDriver.ExecuteJavaScript(javaScript);
var errormessagecopy = WebDriver.FindElement(By.Id("errormessagecopy"));
new Actions(WebDriver).MoveToElement(errormessagecopy).Click().KeyDown(OpenQA.Selenium.Keys.Control).SendKeys("v").KeyUp(OpenQA.Selenium.Keys.Control).Perform();
var errorText = WebDriver.ExecuteJavaScript<string>("return $(\"#errormessagecopy\").val();");
You can use https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API but as described in the documentation to read the value from it you need to grant permission in the browser. After you have permission simply execute js script on-page from selenium and get that value.
Related
I'm trying to automate the drop down field value using c# selenium. I use the following code snippet for select the drop down value and as well as the option.
Code
But I'm not able to click that option .If I trying to write a click functionality for the selected option I'm getting error.
Cannot click on option element.Executing javascript function returned an un expected error,but no error could be returned from IE's
javascript Enginge. .
Please refer the following Screen shot for the Error reference .
Error reference
How can I change the value in dropdown using selenium c# ?
I'm not familiar with C# but this is how you'd do it in java. I believe the syntax is similar so maybe someone can translate it or something?
List<WebElement> dropdown = driver.findElements(By.cssSelector("Your css/xpath/whatever here");
for (int i =0;i<dropdown.size();i++){
WebElement ele = dropdown.get(i);
String textOfElementYouWantToClick = ele.getText();
if(textOfElementYouWantToClick.contains("Value you are looking for")){
ele.click();
System.out.println("Selecting the value you chose");
}
}
Try using the SelectElement class. It has methods for handling dropdown fields.
https://seleniumhq.github.io/selenium/docs/api/dotnet/html/T_OpenQA_Selenium_Support_UI_SelectElement.htm
Have you tried not using javascript to click selected option?
There is Select selenium class to handle dropdowns:
Select myDropdown = new Select(dropdownWebElement);
myDropdown.selectByVisibleText('Value to select');
The other reason for it might be the dropdown is rendered with some framework that keeps actual Select hidden and what you see on screen is actually items from very different element in your DOM.
I need to check pictures extension when user has chosen picture and try to upload it into picture library.
I've found the way to edit master page with js script, but i haven't to edit master page. Then i try to use event receiver Adding, but it can't get the name of file or file path. I used:
var file = properties.ListItem.File.Name; //properties.ListItem - returns null
AfterProperties also returns null.
The another way i see is to edit Adding Picture form with js:
I think is's simplest way but i can't found information about it.
Problem: how to set js script to the form (see picture) or how to do such actions with another way
It can be realized with event receiver ItemAdding and with
properties.AfterUrl
The same answered question with code in:
Customizing upload file functionality in SharePoint picture library
In your case, a simple JS form validation will do.
First I would prevent default action of the submit button.
Then, I would analyze the contents of the filename textbox and check the extention. If it's not one of the listed in the validation script, return false + alert "THis file extention is not supported".
Why would you want to use event receiver? It catches the event on server side.
i use the wpf webbrowser control to show manual generated html code via WebBrowser.NavigateToString() method. In this html code there are many manual links like the following example:
Go to Mark 1
When i click on this link in the html document thr browser jump to it. It works correctly. What i want is to jump to the marker via c# code. I know that the WebBrowser.Document Property is a IHtmlDocument from Microsoft.mshtml.dll. I cast it an the enumarte through all IHtmlAncorElements. The i find the Ancor via name and cast it back to IHtmlElement. So i have the IHtmlElement object but i dont no how can i cation the link like also in this mock-code:
var ancorElement = ((IHtmlDocument)WebBrowser.Document).all.Cast<IHtmlElement>().Where(element => elment is IHtmlAncorElement).FirstOrDefault(element => element.href.equals("#marker_1"));
if (ancorElement != null) /* so i don't know the right way */ ancorElement.Click() or ancorElement.Action()
So i hope any know a way to run the link via c# code!
Best regards
Daniel
if (ancorElement != null)
WpExample.Navigate("your URL");
Is this what you mean? i have found it hard to understand your question but to navigate to different URL using WPF you can do it this way?
I am writing a simple personal app that has a browser control and I want it to automatically "Refresh" gmail to check it more often than it does by default. There are monkey scripts that do this but I'm trying to add my personal style to it.
Anyhow, I've looked around and found everything but what I can do in csharp using the browser control.
I found this:
// Link the ID from the web form to the Button var
theButton = webBrowser_Gmail.Document.GetElementById("Refresh");
// Now do the actual click.
theButton.InvokeMember("click");
But it comes back with null in 'theButton' so it doesn't invoke anything.
Anyone have any suggestions?
It's been awhile since I've used JavaScript, but given the other answers and comments that there is no real ID associated with the element, could you do something like the following:
Search all Div's with an attribute of Role == 'Button' and an InnerHtml == 'Refresh'.
Once the correct InnerHtml is found, get the Element.
Invoke the click on the found Element.
Again, this may be blowing smoke, but thought I'd throw it out there.
edit: Just realized you are doing this with C# and a browser control; however, the concept would still be the same.
The best suggestion I could give you at this point involves an existing API that is used for .NET web browser based automation:
http://watin.org/
Since the div tag with the desired button really only seems to identify itself with the class name, you could use the Find.BySelector(“”) code included with the most recent version of watin.
If instead of navigating to a webpage in a WebBrowser, you want to set the HTML property directly, what's the proper way to do it?
Is it like this?
myWebBrowser.Navigate("about:blank");
myWebBrowser.Document.Write("<html><body>Test</body></html>");
Using this (instead of the about:blank document.write combo):
myWebBrowser.DocumentText = sourceCode;
seems to solve various issues such as running the following JavaScript when IE7 is installed on the system:
window.location = "#test";
If IE 7 is installed, this will cause an Error: Invalid argument message to appear.
You can also use WebBrowser.DocumentStream Property to write the data you need.