Is it possible to use CMD + CLICK Element A + CLICK Element B - katalon-studio

I cannot use the Katalon recorder to click on the Element with CMD Key. Is it possible to click on two different items while the CMD key is pressed?
I tried to do that with sendKeys, controlKeyDown, keyDown Commands and then call Click Command on first element and then call Click Command on second element. But nothing happens.
Also, if we can simulate with CLICK Element A then CMD + CLICK Element B it can be ok for me.

In Katalon Studio (not the recorder) switch to script mode:
Now you can write scripts in Groovy!
Next, try using Actions class, like this:
WebUI.openBrowser("url of the page you are testing")
WebDriver driver = DriverFactory.getWebDriver()
WebElement targetA = driver.findElement(By.cssSelector("element-a-selector"))
WebElement targetB = driver.findElement(By.cssSelector("element-b-selector"))
targetA.click()
Actions actions = new Actions(driver)
actions.keyDown(Keys.CONTROL).click(targetB).keyUp(Keys.CONTROL).perform()
Note that this is your second scenario, first clicking element A (you will need to add the CSS selector or any other way of identifying it) and then holding CTRL and clicking element B.
The first one (press CTRL, click element a, click element b, release CTRL) is similar, just change the last line to:
actions.keyDown(Keys.CONTROL).click(targetA).click(targetB).keyUp(Keys.CONTROL).perform()
and remove targetA.click().
You will need to import the following Selenium helper classes:
import org.openqa.selenium.By
import org.openqa.selenium.Keys
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement as WebElement
import org.openqa.selenium.interactions.Actions

Related

Drag a file from my GTK app to another app (not the other way around)

I have searched for examples, but all the examples were the opposite direction (my app is getting file drag-and-drop from another application). But this must be possible because I can drag a file from Files (Nautilus) to another app, Text Editor (gedit).
Could you show me a very simple example of a GTK Window with one widget on it, and when I drag from the widget to Text Editor, it passes a text file on the system (such as /home/user/.profile) to the Text Editor so that it will open the text file?
In order to make it so that your application can receive files, you need to use uri. In the function you bind to drag-data-received, you can use data.get_uris() to get a list of the files that were dropped. Make sure that you call drag_dest_add_uri_targets(), so that the widget can receive URIs.
This code example has one button that drags a file, and another button that can receive it. You can also drag the file and drop it into any file-receiving app, such as gedit (Text Editor) or VSCode.
import gi
gi.require_version("Gdk", "3.0")
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk
window = Gtk.Window()
window.connect("delete-event", Gtk.main_quit)
box = Gtk.HBox()
window.add(box)
# Called when the Drag button is dragged on
def on_drag_data_get(widget, drag_context, data, info, time):
data.set_uris(["file:///home/user/test.html"])
# Called when the Drop button is dropped on
def on_drag_data_received(widget, drag_context, x, y, data, info, time):
print("Received uris: %s" % data.get_uris())
# The button from which the file is dragged
drag_button = Gtk.Button(label="Drag")
drag_button.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, [], Gdk.DragAction.LINK)
drag_button.drag_source_add_uri_targets() # This makes sure that the buttons are using URIs, not text
drag_button.connect("drag-data-get", on_drag_data_get)
box.add(drag_button)
# The button into which the file can be dropped
drop_button = Gtk.Button(label="Drop")
drop_button.drag_dest_set(Gtk.DestDefaults.ALL, [], Gdk.DragAction.LINK)
drop_button.drag_dest_add_uri_targets() # This makes sure that the buttons are using URIs, not text
drop_button.connect("drag-data-received", on_drag_data_received)
box.add(drop_button)
window.show_all()
Gtk.main()
Mr Kruin's answer was for Python's GTK. The language I actually wanted was C#. Using his code as a hint, I modified the default GtkApplication project like so, and it worked on Linux.
private MainWindow(Builder builder) : base(builder.GetRawOwnedObject("MainWindow"))
{
builder.Autoconnect(this);
DeleteEvent += Window_DeleteEvent;
_button1.DragDataGet += (o, args) =>
{
args.SelectionData.SetUris(new string[]{fullFilePath});
};
Gtk.Drag.SourceSet(_button1, Gdk.ModifierType.Button1Mask,
new TargetEntry[0],
Gdk.DragAction.Link);
Gtk.Drag.SourceAddUriTargets(_button1);
}
On Windows, however, it did not work. I have tried both string fullFilePath = "file:///c:/windows/win.ini" and string fullFilePath = "c:\\windows\\win.ini" and none of them seemed to work.

Protractor version 5.2.0 (Latest) - How to simulate keyboard key presses- TAB, ENTER?

Following NOT working:
browser.actions().sendKeys(protractor.Key.TAB);
browser.actions().sendKeys(protractor.Key.ENTER);
it('validate the upload portfolio feature', function() {
//loginPage.loginToPRA(); // not needed
element(by.custLoc(ObjRep.validateUploadPortfolio.portUpload)).click();
browser.actions().sendKeys(protractor.Key.TAB);
browser.actions().sendKeys(protractor.Key.ENTER);
browser.sleep(3000);
});
In Browse code button locator:
class="text-white background-teal cursor-pointer overflow-hidden padding-vertical-5 padding-horizontal-20 border-radius-4 border-shadow vertical-align-middle"
You're mixing two ways of Key-Inputs.
Selenium Way: browser.actions()
If you use browser.actions(). you use the Selenium-Way and you must end it with perform() to execute the action.
Find here in this Protractor API a short description plus a link to the detailed Selenium description with all possible key-actions.
Protractor Feature element.sendKeys():
Here you actually don't need browser.actions()., but element., because according to the Protractor API description here .sendKeys() is a property/function followed after an element.
So all described in Code (I'm only using element.sendKeys(), so I didn't test the Selenium-Way)
//SELENIUM-ACTION SEQUENCE IN PROTRACTOR
//Press first TAB, execute it, then Enter, execute it. The current cursor position doesn't matter
browser.actions().sendKeys(protractor.Key.TAB).perform();
browser.actions().sendKeys(protractor.Key.ENTER).perform();
//Press TAB then ENTER fast one after the other
browser.actions()
.sendKeys(protractor.Key.TAB)
.sendKeys(protractor.Key.ENTER)
.perform();
//PROTRACTOR
//focuses first the cursor to "element", then presses [TAB]
element.sendKeys(protractor.Key.TAB);
//focuses first the cursor to "element", then presses [ENTER]
element.sendKeys(protractor.Key.ENTER);

Surround selection with method call

Often when I'm writing code I forget to surround a section of code with a method. For example, when printing an array, I realize that I forgot to pass the array into Arrays.toString().
String[] foo(){
return new String[3];
}
main() {
System.out.println(foo());
}
Is there a way in Eclipse that I can select foo() and then use auto complete or something to surround it with Arrays.toString()? So I want to end up with this:
main() {
System.out.println(Arrays.toString(foo()));
}
I know I could use templates, but I would have to make a template for each method I want to use. I'm looking for something like Eclipse's auto complete feature, which knows about every class and method in the build path.
Yes, you could use templates for that:
First, experiment with existing templates:
Go to the source editor and select "foo()".
Open the view General > Templates.
Select some template, for example, Java > toArray and see how it works.
Then, add your own template:
Windows > Preferences > Java > Editor > Templates > New.
I think the right context should be "Java".
Another way of accesing templates is through the content assist: In the source code, in a new line, start typing the first letters of your template, then press [CTRL][SPACE]. A selector will appear with the matching templates. You may find it useful to check the checkbox "Automatically inserted" in the template definition window.
And yet another way to access them is to select a line of code and then Context Menu > Surround With.
A quick way:
Double click or use select enclosing element and its cousins to select the expression you wish to wrap. ctrl-x to temporarily cut it. Type a few characters and ctrl-space to insert your method name and parentheses. Finally, ctrl-v to paste what you just cut.
with templates - under Java Statements: ${method}(${word_selection})${cursor}
You can make a template like the one described by #LittleSanti. If you use a fake template variable for the method name (like ${method} or ${name}) instead of a constant like foo, Eclipse will highlight it and let you paste or type or complete over it. Then when you hit return or tab, it will jump the cursor to the end (the position indicated by ${cursor}
Unfortunately I don't think Eclipse provides a "real" template variable for selecting methods in scope. It would be nice if it would let did completion for you on methods.

Right click in selenium webdriver problems

I've found this code here: https://stackoverflow.com/a/22376627/4165083
Actions oAction = new Actions(driver);
oAction.moveToElement(Webelement);
oAction.contextClick(Webelement).build().perform(); /* this will perform right click */
WebElement elementOpen = driver.findElement(By.linkText("Open")); /*This will select menu after right click */
elementOpen.click();
But I'm having problems with driver: "Cannot resolve symbol driver". I can't import anything. What should I do to get it working in my tests in Scala?
I believe you are referencing to wrong element. You have to reference to the element you are trying to right click on;
WebElement elementToRightClickOn = driver.findElement(By.id("something"));
Actions oAction = new Actions(driver);
oAction.moveToElement(elementToRightClickOn);
oAction.contextClick(elementToRightClickOn).build().perform(); /* this will perform right click */
WebElement elementOpen = driver.findElement(By.linkText("Open")); /*This will select menu after right click */
elementOpen.click();
"Cannot resolve symbol driver" - Check have you created the instance of the WebDriver and is accessible.
For Actions class - import org.openqa.selenium.interactions.Actions;
Provide complete code to assist.

Select element and click

I desire to use watir webdriver to click on a link on a webpage. If I use firebug to find the unique selector - I obtain the following:
new_login > div:nth-child(6) > button:nth-child(1)
How can I select and click this button using watir-webdriver?
Clicking a direct translation of your xpath would be:
browser.element(:id => 'new_login').div(:index => 5).button.click
Depending on the actual html, you may be able to simplify it. For example, if there is only one button in the new_login element, you could just do:
browser.element(:id => 'new_login').button.click
The fewer things you need to locate the button, the more robust and maintainable your script will be.