Are there any work around to make HTML5 Drag and Drop work in IE11 with Selenium Webdriver with java? I am using Selenium-Webdriver 3.4
Please find the attached for more details about the HTML. I have used the below Locator to locate the elements which works fine with Action class in chrome but not in IE11.
Web Element Initialisation
#FindBy(how = How.CSS, css =".work-card-description.searchable-field")
private WebElement weDragFrom;
#FindBy(how = How.CSS,css = "div.resource-schedule.resource-ui-droppable
div.hour-line:nth-of-type(11)")
private WebElement weDragTo;
Please find the Attached
Related
I have the following WebElement which can locate using xpath:
/html/body/div/div/div/div[2]/div[1]/div[4]/div/div/div[335]/div[1]/span
In the above locator, div[335] number randomly changes. I want to use regex and use the xpath as element locator.
Can anyone please let me know the regular expression to use with the above xpath?
I'm using Selenium Webdriver with Java. IDE is Intellij and I'm testing on Chrome browser.
I'm going to use the above mentioned xpath as below:
#FindBy(how = How.XPATH, using =/html/body/div/div/div/div[2]/div[1]/div[4]/div/div/div[335]/div[1]/span
public WebElement totalSuppliers;
I'm trying to test drag and drop functionality using selenium webdriver while writing test scripts using java in eclipse.I'm unable to find the web element that I want to drag while my other friend is able to find the element with same code.
Below is the code we both have used.
WebElement draggable = driver.findElement(By.id("draggable"));
I'm using site www.way2automation.com/demo.html and the page i'm trying to find webelement on, is http://way2automation.com/way2auto_jquery/draggable.php
Please suggest something to find the webelement.
Try this below code, using Action Class.
WebElement from = driver.findElement(By.id("drag"));
WebElement to = driver.findElement(By.id("drop"));
Actions act = new Actions(driver);
act.clickAndHold(from).build().perform();
Thread.sleep(3000);
act.clickAndHold(to).moveToElement(to).release(to).build().perform();
Thread.sleep(2000);
WebElements were not being identified even with right locators because these webElements were under an iFrame so First we need to switch to the iFrame before performing drag and drop. And then we also need to check for the availability of SourceElement and DestinationElements. Below code is working fine for this problem.
//Wait for the frame to be available and switch to it
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector(".demo-frame")));
WebElement Sourcelocator = driver.findElement(By.cssSelector(".ui-draggable"));
WebElement Destinationlocator = driver.findElement(By.cssSelector(".ui-droppable"));
builder.dragAndDrop(Sourcelocator,Destinationlocator).build().perform();
String actualText=driver.findElement(By.cssSelector("#droppable>p")).getText();
Assert.assertEquals(actualText, "Dropped!");
I am using selenium webdriver. I am unable to access link menu options.eg:I want to access options "Casual shoes" option under "Men" menu link from flipkart site. i tried using below code
WebElement a= driver.findElement(By.xpath("//a[title='Men']"));
a.click();
but unable to click on menu link "Men"
Your XPath is wrong you forget to add # in front of attribute. You are using //a[title='Men'] but you should use //a[#title='Men']
Below code is working for me:-
driver.get("http://www.flipkart.com/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.xpath("//a[#title='Men']")).click();
driver.findElement(By.xpath("//span[contains(.,'Casual Shoes')]")).click();
OR
In chrome below code is working fine for me:-
WebElement we =driver.findElement(By.xpath("//a[#title='Men']"));
we.click();
WebElement Causual =driver.findElement(By.xpath("//span[contains(.,'Casual Shoes')]"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", Causual);
Hope it will help you :)
Is there any way by which we can remove a web-element from the the source of the page.
I have the problem that there is a division of popup in the webpage source which is disabling all other divisions. If we remove this division while doing inspect element from a browser all other elements are automatically enabled for use.
How can I do this in selenium webdriver?
To my knowledge, there is no direct Java method, but you can use the JavaScriptExecutor API to do something like:
WebElement yourElement = …
JavaScriptExecutor jsExecutor = (JavaScriptExecutor) webDriver;
jsExecutor.executeScript(
"arguments[0].parentNode.removeChild(arguments[0])", yourElement);
I am using XPath, HtmlUnitDriver & FirefoxDriver.
Here is the my xpath to click on the signin button. When I use XPath
//div[#id='mainPane']/form/table/tbody/tr[10]/td/a[2]
to click on sign in button then it is working fine with FirefoxDriver but not working in HtmlUnitDriver.I have also enabled & disabled the javascript in HtmlUnitDriver.But not working.
I am getting Error:- When I click on this sign in button using HtmlUnitDriver,then it is not redirecting to next page,but in FirefoxDriver,it is redirecting to next page.Here is my code:-
HtmlUnitDriver driver = new HtmlUnitDriver(false);
WebElement webElement = webDriver.findElement(By.xpath("//div[#id='mainPane']/form/table/tbody/tr[10]/td/a[2]"));
webElement.click();
Please guide me.
As #David Grant suggests your problem might be related to the Javascript.
Enable your javascript in the HtmlUnitDrive -
HtmlUnitDriver driver = new HtmlUnitDriver(true);