I'm trying to cancel the pop up download windows in Firefox with selenium. I can switch windows and close alert windows, but I can't seem to select the download window. Any ideas?
Looking around, it seems Selenium RC can't do handle the download window because they depend on the OS. However, is this problem the same for the Selenium Web Driver? I know a solution to this can be done with autoit, but I'd like to keep it all in Java selenium if possible. Thanks.
WebDriver cannot directly interact with dialog windows this is because dialog windows are the domain of the operating system and not the webpage. However its possible to do actions on dialog windows using
SendKeys class method SendWait() of name space System.Windows.Forms
using System.Windows.Forms;
In the example code below a PLUpload button is pressed, which opens a Windows Dialog to select the file to upload.
Following lines are written to send key values to the dialog window displayed.
SendKeys.SendWait(#"C:\Users\Public\Pictures\Sample Pictures\Dock.jpg");
SendKeys.SendWait(#"{Enter}");
Detailed reference of SendKeys class in C# can be found in http://msdn.microsoft.com/en-au/library/system.windows.forms.sendkeys.aspx
using System;
using System.Windows.Forms;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium;
using OpenQA.Selenium.Support;
using OpenQA.Selenium.Interactions;
using NUnit.Framework;
namespace BusinessCreation
{
class PlUpload
{
static void Main(string[] args)
{
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://www.plupload.com/example_queuewidget.php");
driver.FindElement(By.XPath("//object[#data='/plupload/js/plupload.flash.swf']")).Click();
SendKeys.SendWait(#"C:\Users\Public\Pictures\Sample Pictures\Dock.jpg");
SendKeys.SendWait(#"{Enter}");
}
}
}
Related
I'm facing the Developer Tools problem since yesterday. I use
Unity (several different versions, e.g. 2018.4.23),
Jetbrains Rider (updated today to 2020.1.3, yesterday 2020.1.2)
macOS Catalina 10.15.5
I was refactoring some stuff and Developer Tools asked me for the access: Developer Tools Access needs to take control of another process for debugging to continue. Enter your password to allow this...
Since then, two things are happening.
If Developer Tools Access is enabled (also tried doing this through sudo /usr/sbin/DevToolsSecurity --enable command) nearly every time when I'm changing something in code, Unity stops working (loading wheel present) and I can't turn its application off. I tried using Activity Monitor, it doesn't show any activities. I can only see the loading wheel.
I even tried killing the Unity process through kill unitypid, it "kills" the process since it's not present on the processes list, but I still can see it on my desktop, being just as down as before.
Checking Unity logs, I can see it stops on:
Begin MonoManager ReloadAssembly
custom-attrs.c:1250: (null)
assembly:/Applications/Unity/Hub/Editor/2018.4.17f1/Unity.app/Contents/Managed/UnityEngine/UnityEngine.CoreModule.dll type:UnityException member:(null) signature:<none>
Stacktrace:
Native stacktrace:
0 libmonobdwgc-2.0.dylib 0x00000001460b4976 mono_handle_native_crash + 242
If Developer Tools Access is disabled, the application asks me a few times to enable it. After pressing Cancel a few times, Unity crashes and turns off and gives me the ability to send log error to Apple with the exception:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Application Specific Information:
abort() called
Don't really know what to do. I tried updating Rider, Catalina, installing a new Unity version.
Update: I formatted the disk and installed Catalina again, it still doesn't work.
Your help would be much appreciated!
After further investigation, I've discovered the following repro:
Create a custom attribute that derives from the PropertyAttribute that calls AssetDatabase.FindAssets("somethingsomething") in it's constructor.
Create a class (in my case it derives from the MonoBehaviour class in order to be able to call the constructor because of the gameObject placed on the scene) that contains a field that has a custom attribute mentioned above.
Add FormerlySerializedAs attribute to this field (e.g. during refactoring).
Create a gameObject with your class attached.
This will result in a pop-up window with a message that I've mentioned in my question:
Developer Tools Access needs to take control of another process for debugging to continue. Enter your password to allow this...
Example:
using System.Diagnostics;
using UnityEditor;
using UnityEngine;
public class CustomObjectPathAttribute : PropertyAttribute
{
/// <summary>
/// Default constructor.
/// </summary>
public CustomObjectPathAttribute()
{
var guids = AssetDatabase.FindAssets("Resources");
}
}
using UnityEngine.Serialization;
[System.Serializable]
public class TestClass
{
/// <summary>
/// Path to the file.
/// </summary>
[FormerlySerializedAs("pathToFile")]
[CustomObjectPath]
public string pathToFile2 = string.Empty;
}
using System.Collections.Generic;
using UnityEngine;
public class MyBehaviour : MonoBehaviour
{
private List<TestClass> testClasses;
void Start()
{
testClasses = new List<TestClass>();
}
}
Attach the MyBehaviour script to the gameObject placed on the scene. The issue will occur after project recompilation.
Using AssetDatabase.FindAssets("Resources") in the custom attribute's constructor works fine if there's no FormerlySerializedAs attribute attached to the field in the TestClass.
I've reported the bug to the Unity QA Team and they successfully reproduced the issue. Here's the link to the Unity Issue Tracker: https://issuetracker.unity3d.com/issues/crash-when-using-assetdatabase-dot-findassets-in-a-custom-propertyattribute-and-when-formerlyserializedas-attribute-is-also-used
There's nothing more I can do at this point except of
not refactoring my fields when they have custom property attributes
attached,
not using AssetDatabase.FindAssets in my property
constructor.
This is happening to me in 2019.3.x
It generally happens when I'm testing animations and making changes while in play mode.
Nothing short of a reboot will fix the issue.
I am trying to automate button presses for a desktop application on Windows 7 - 10. I have been able to do this using AutoHotKey and PowerShell. However, I have had the following issues:
The controls I am trying to click do not have text that I can use to
isolate the control
The ClassNN name for the components is not
static
I have looked through the MSDN documentation for the System.Windows.Automation namespace, but the documentation doesn't provide actual examples or describe how to use the namespace.
Question
If I always have a window handle (HWND) and an Automation ID for a control, how do I invoke a button press on the control using AutoHotKey, PowerShell(3.0+), or C#?
You can do it with C# and System.Windows.Automation.
First of all get your control as an AutomationElement (let's call it thiselement).
Then you can invoke InvokePattern to perform click action.
InvokePattern ip;
ip = thiselement.GetCurrentPattern(InvokePattern.Pattern) as
InvokePattern;
ip.Invoke();
Suppose your window handle is 'handle' and automation id of the button is 'automationId' then you can do something like
AutomationElement parentWin = AutomationElement.FromHandle(handle);
Condition c1 = new PropertyCondition(AutomationElement.AutomationIdProperty,
automationId);
AutomationElement thiselement = parentWin.FindFirst(TreeScope.Descendants, c1);
once you get the button object,just invoke the InvokePattern .Please forgive the foramatting of text
I want to drag and drop one element.But it is working fine in some version of Firefox browser but for other version it is not working(Means drag and drop). I have not changed any code written in selenium web driver but still It is is behaving unexpectedly.
code sample:
if(dragElement.isDisplayed() && dropElement.isDisplayed())
{
Actions action = new Actions(getWebDriver());
action.clickAndHold(dragElement);
action.moveToElement(dropElement).release().build().perform();
}
I am working on Visual Studio 2010. I've developed a WPF C# application which will be deployed to customers trough a website. After downloading and installing it they will have to register the application which will send info to the server and also write some registry entries.
I have created a Setup Project in order to create the installer package for my app. It installs correctly and auto-registers the app in Control Panel/Add Remove programs, which is great if the user wishes to uninstall the program some day.
Question: How can I force the uninstaller to execute some code or launch another application in order to send info to the website that the current user is deactivating and uninstalling the program?
The Problem: If the user uninstalls the program as it is right now, only the files are deleted, and eventually the registry values, but the website will continue to think the user still has an active copy of the software and if he wants to download it again, the website would not let him do it.
You have to implement install actions, and run them in the appropriate set up event.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Deployment.WindowsInstaller;
namespace CustomAction1
{
public class CustomActions
{
[CustomAction]
public static ActionResult CustomAction1(Session session)
{
session.Log("Begin CustomAction1"); // Here you can write your own custom action code
return ActionResult.Success;
}
}
}
Select the CustomAction1.CA.dll file and add it to your Advanced Installer project
Go to Custom Actions Page, add a “New Installed Custom Action” with sequence from Add Custom Action Tab or the toolbar and select CustomAction1.CA.dll
In the "Function Name" field from the "Custom Action Properties" view select CustomAction1
Build the project and test it
http://www.advancedinstaller.com/user-guide/qa-c-sharp-ca.html
If your setup project is a Visual Studio setup project, then basically you just need to add a custom action for install and one for uninstall. This is old but still relevant - you can arrange to run a program at the end of the install and on an uninstall:
Getting Stsrted with Setup Projects
I'm attempting to launch the devtools in a chrome browser on Linux by using the keyboard shortcuts. Because I'm using Ruby and it does not have a chord method, I've tried the following:
driver.action.key_down(:shift)
.key_down(:control)
.send_keys("i")
.key_up(:shift)
.key_up(:control)
.perform
The above code will work in Firefox (as suggested in Key press in (Ctrl+A) Selenium WebDriver), but in chrome, it returns nil but no results occur.
Any advice?
In Selenium I have used :
function key F12.
driver.FindElement(By.XPath("String")).SendKeys(Keys.F12);
I think you're just using a wrong keys combination. According to this: https://support.google.com/chrome/answer/171571?hl=en&ref_topic=25799, the shortcut to open Developer Tools is Ctrl-Shift-J on Linux and Windows and Cmd-Opt-I on Mac.
You can use robot class of java, if you want to open dev-tools.
try{
Robot robot=new Robot();
robot.keyPress(KeyEvent.VK_F12);
robot.keyRelease(KeyEvent.VK_F12);
}
catch(Exception ex){
System.out.println(ex.getMessage());
}