How to send right and left cursor using Soda/Selenium? - selenium

I'm using Soda to run Selenium Webdriver. Mostly it's working as expected but I'm trying to figure how to send the right and left cursor keys to the browser to move a jquery ui slider handle.
I tried
.typeKeys('css=a.ui-slider-handle[lr="l"]','\37')
and
.type('css=a.ui-slider-handle[lr="l"]','\37')
and
.typeKeys('\37')
and
.type('\37')
Nothing seems to move the slider. None of them error either. I'm sending a click to the handle before I do this just to be sure...
Anyone know how to do this?

Working code in Java-
WebDriver driver = new InternetExplorerDriver();
driver.get("http://jqueryui.com/demos/slider/");
//Identify WebElement
WebElement slider = driver.findElement(By.xpath("//div[#id='slider']/a"));
//Using Action Class
Actions move = new Actions(driver);
Action action = move.dragAndDropBy(slider, 30, 0).build();
action.perform();
driver.quit();
Source - https://gist.github.com/2497551

Try below, I tested this in firefox with jquery UI slider page and it worked for me.
.clickAt("//div[#id='slider']/a[1]", "")
//mouse left key down
.mouseDownAt("//div[#id='slider']/a[1]", "0,0")
//move the cursor some 200 from left
.mouseMoveAt("//div[#id='slider']", "200,0")
//Release the mouse button
.mouseUpAt("//div[#id='slider']", "");

Related

Mouse hover is not working correctly in IE11 and firefox

I am trying to mouse hover on an element using Action class and then trying to go to other sub element and click, but my mouse hover is pointing some where else.
These are the IE capability which are set for IE and action class code
InternetExplorerOptions options = new InternetExplorerOptions();
options.enablePersistentHovering();
options.ignoreZoomSettings();
driverinstance = new InternetExplorerDriver(options);
WebDriverWait myWaitVar = new WebDriverWait(driver, const_waithigh);
myWaitVar.until(ExpectedConditions.elementToBeClickable(By.xpath(element1)));
Actions action = new Actions(driver.get());
action.moveToElement(driver.findElement(By.xpath(element1))).click().build().perform();
Even if you ignore zoom using options.ignoreZoomSettings(); IE doesn't calculate the correct position of the element unless your application is fully maximized and zoomed at 100%.
so use the below code once you initialize the driver instance for IE.
driver.manage().window().maximize();
driver.findElement(By.tagName('html')).sendKeys(Keys.chord(Keys.CONTROL, "0"));
We are essentially maximizing the window and pressing CTRL+0 to set to the zoom to default level. See if this fixes your issue.

Selenium: Click and Hold the element and then Slide it

In my application I have a scenario where I need to slide an element in list view to add new entry to the item. I have to automate it using Selenium and C#. Application is developed using Ionic and Angular Frameworks.
In Selenium there is an option to ClickAndHold and MoveByOffset methods but none of these seems to be working. At the same time no errors are displayed. Please help.
Code I have tried so far is as below.
Actions dragger = new Actions(driver);
elementToSlide = driver.FindElement(By.XPath("//ion-item-slide[1]"));
dragger.ClickAndHold(elementToSlide).MoveByOffset(-47,0).Build().Perform();
Images are attached for reference. The first element in the list view slides.
Maybe the drag and drop command could solve your problem,try like this
IWebElement elementToSlide = driver.FindElement(By.XPath("//ion-item-slide[1]"))
Actions dragger = new Actions(driver);
dragger.DragAndDropToOffset(elementToSlide, -47, 0).Build().Perform();
I had the same problem, I wrote the code like this and it worked for me:
Actions action = new Actions(driver);
action.clickAndHold(elementToSlide);
action.moveToElement(NextplaceElement).release();
action.build().perform();
Thanks for your answers, actually I figured out in ionic framework we should not use ion-item-sliding element for sliding, but the next child which is ion-item. I did by using the following code.
var slidableItm = driver.FindElement(By.XPath("//ion-item-sliding/ion-item");
Actions dragger = new Actions(driver);
dragger.ClickAndHold(slidableItm))).MoveByOffset(-47, 0).Build().Perform();
Then after sliding we need to click on some element's coordinates to complete and release the slide. It can be achieved by following code.
var clickableItm = driver.FindElement(By.XPath("/ion-item-sliding/ion-item/div[1]/div/ion-label/div/p[1]"));
ILocatable c = (ILocatable)clickableItm;
RemoteWebDriver rd = (RemoteWebDriver)driver;
rd.Mouse.Click(c.Coordinates);
Actions a = new Actions(driver);
a.clickAndHold(e2).pause(2000).moveToElement(e1).release().build().perform();

Selenium: move Mouse

Task is to move physical cursor to the element.
Driver correctly finds element on the page.
WebElement label = driver.findElement(By.xpath("//form[#id='loginForm']")).
Move cursor does not work.
Tried following:
Actions act = new Actions(driver);
act.moveToElement(label, 1, 1).click().build().perform();
And following:
Actions act = new Actions(getDriver());
act.moveToElement(label).build().perform();
Try this.
driver.findElement(By.xpath("//form[#id='loginForm']")).equals(driver.switchTo().activeElement())
Solution was to use Robot class and use there - mouseMove

program stuck using drag and drop selenium

I am trying to move slider using drag and drop. It identifies the element and clicked on it and after that nothing happens and my code stuck there itself(like waiting for user input). As soon as i moved my mouse little bit manually it executes rest of the code and works as expected. please help me what is this weird behavior.?. below is the code i used to build drag and drop.
Actions builder = new Actions(driver);
Action secondSlide = builder.dragAndDropBy(secondSlider, 50, 0).click().build();
System.out.println("waiting");
secondSlide.perform();
System.out.println("not waiting");
"Waiting" message is printing nicely but it doesn't print "not waiting" as it stuck in "secondSlide.perform()" line. But as soon as i moves my mouse little bit manually it prints "not waiting" and program ends gracefully.
Try to do it differently. Here is a number of approaches:
WebElement element = driver.findElement(By.name("element dom name"));
WebElement target = driver.findElement(By.name("target dom name"));
(new Actions(driver)).dragAndDrop(element, target).perform();
Or:
Actions builder = new Actions(driver);
Action dragAndDrop = builder.clickAndHold(someElement)
.moveToElement(otherElement)
.release(otherElement)
.build();
dragAndDrop.perform();

how can you do right click using selenium?

im trying to preform a right click using selenium, any thoughts on how to do this?
According to the OpenQA.Selenium.Interactions Namespace.
// step 1 - select the element you want to right-click
var elementToRightClick = this.Driver.FindElement(By.Id("elementtoclickonhasthisid"));
// step 2 - create and step up an Actions object with your driver
var action = new OpenQA.Selenium.Interactions.Actions(this.Driver);
action.ContextClick(elementToRightClick);
// step 3 - execute the action
action.Perform();
Please see docroots's answer for selenium.
To generally simulate a right click in JavaScript, have a look at JavaScript simulate right click through code.
it appears that for my issue (an element that opens a popup after a right click), using selenium's : mouse_down_right() and then mouse_up_right()
worked as well. thanks.
Selenium is offering a method for right click - ContextClick:
public void RightClick(IWebElement target)
{
var builder = new Actions(driver);
builder.ContextClick(target);
builder.Perform();
}
I've tried ActionSequence and it worked.
ContextClick function is not found, you should use click.
So, it should be as follows:
driver.actions().click(element,2).perform();
The element is your web element, 2 means right click.