I've been looking for a way to set a slider value on a website to a specific value using visual basic.
The way I grab the slider:
Dim slider As WebElement = driver.FindElement(By.XPath("//*[#id='main-content']/div[1]/div[2]/ul/div/div[5]/div[2]/div/input"))
The element does have a default value "50". I'd like to set it to, say, "30"
A code block I found:
Actions move = new Actions(driver);
Action action = move.dragAndDropBy(slider, 30, 0).build();
action.perform();
which is not VB.NET
How do you do that using VB.NET?
Related
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.
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();
I have to click on a tile which is generated after mouse hovering. I wrote the code below but it is still not working.
WebElement FrontElement=driver.findElement(By.xpath("//a[#class='sol-itm-bx relative front-app-nm']/span[text()='UI Auto Test12345']"));
WebElement BackElement= driver.findElement(By.xpath("//a[#class='relative back-app-desc']/span[text()='UI Auto Test12345']"));
Actions builder = new Actions(driver);
builder.moveToElement(FrontElement);
builder.perform();
builder.clickAndHold(FrontElement);
BackElement.click();
To use the Actions() class you need to chain the actions together. Separate commands won't work in the way you want.
Actions builder = new Actions(driver);
builder.moveToElement(driver.findElement(By.xpath("//a[#class='sol-itm-bx relative front-app-nm']/span[text()='UI Auto Test12345']")))
.moveToElement(driver.findElement(By.xpath("//a[#class='relative back-app-desc']/span[text()='UI Auto Test12345']")))
.click().perform();
Note: I've separated the lines for ease of reading.
EDIT: 'build' to 'builder' NullPointerException
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();
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']", "");