I try to select multiple options from list but it does not select particular option it select from first choose options to last choose option and give some error like:
Cannot perform native interaction: Could not get node for element - cannot interact
My code is looks like
WebDriver driver=new FirefoxDriver();
driver.get("http://jqueryui.com/selectable/");
driver.manage().window().maximize();
driver.switchTo().frame(driver.findElements(By.tagName("iframe")).get(0));
WebElement multiSelectDropDown=driver.findElement(By.className("ui-selectable"));
List<WebElement> dropdownlists = multiSelectDropDown.findElements(By.tagName("li"));
Actions builder=new Actions(driver);
builder.clickAndHold(dropdownlists.get(0)).
clickAndHold(dropdownlists.get(4)).click()
.build().perform();
Can any one tell me why this is not working is there any problem in my code.
I think you need to change this
builder.clickAndHold(dropdownlists.get(0)).
clickAndHold(dropdownlists.get(4)).click()
.build().perform();
This should be looks like
builder.clickAndHold(dropdownlists.get(0)).moveToElement(dropdownlists.get(4)).
release().build().perform();
because in real world click the mouse and drag to the other element so moveto another element and then release the mouse.
Related
I am doing automation using selenium webdriver (java) on a search engine BookMyCrop (http://www.bookmycrop.com). Here, I searched for a crop but, I am not able to click on desired search result. Please help me with it.
Code :
WebElement search = driver.findElement(By.xpath("//*[#id=\"search_keyword\"]"));
search.sendKeys("59825");
search.sendKeys(Keys.ENTER);
driver.findElement(By.partialLinkText("Cashew")).click();
------My 1st try-------------
//WebElement link = driver.findElement(By.xpath("\"//div[#id = 'Links']/a[3]\""));
//link.click();
------My 2nd try-------------
//List<WebElement> find = driver.findElements(By.xpath("/html/body/section[2]/div[2]/div/div/div/div[1]"));
//find.get(1).click();
}
} –
You can use the css selector based on class names: ".product-block.inner-product-block" and get the list of all the search results.
Then click on whatever index you want to click.
I am not using an IDE for this but it would look something like this:
driver.findElements(By.cssSelector(".product-block.inner-product-block")).get(0).click();
As said, you can try with css ".product-block.inner-product-block"
Then
get List of WebElements
do loop
inside loop, try get text of each element or innerText attribute
cross check if it is required one or not by simple if condition
If so, click on that web element and break loop
if this locator is not giving required info, try other locator. say $$("a h3") for veg names.
The below code worked for me. It is navigates to the correct link
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().setScriptTimeout(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("http://www.bookmycrop.com");
WebElement search = driver.findElement(By.xpath("//*[#id=\"search_keyword\"]"));
search.sendKeys("59825");
search.sendKeys(Keys.ENTER);
driver.findElement(By.partialLinkText("Cashew")).click();
I tested first if the first line of code to click the XPath which works but then when I add a second line of code to click By.name() it doesn't work, so I tried to change in XPath and then in CSS selectors but it only clicks the first one the (XPath code of line). I have tried but it doesn't seem to click the two other elements.
What I found out was that it only clicking what was on the first page, didn't really matter what was on the new page and I told to click on an element that I wanted to do. I'm using the Selenium version 3.141.59.
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\ae65255\\Desktop\\java_gui\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://shop.palaceskateboards.com/collections/new");
driver.findElement(By.xpath("//*[#id=\"product-loop\"]/div[#data-alpha='S-LINE JOGGER BLACK']")).click(); //only this one work
driver.findElement(By.name("button")).click(); //second click dosen't work?
driver.findElement(By.linkText("Cart")).click(); //this dosen't work too?
}
Add some wait to let the page load before locating the element
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement button = wait.until(ExpectedConditions.elementToBeClickable(By.name("button")));
button.click();
The third locator By.linkText("Cart") didn't work because the button doesn't have Cart text, it's in the data-text and value attributes.
As a side note, you should use By.partialLinkText() when looking for partial text.
webDriver driver = new FirefoxDriver();
driver.get("https://www.ignitionone.com/company/careers/");
driver.manage().window().maximize();
Thread.sleep(2000);
driver.findElement(By.xpath("html/body/div[1]/section[1]/div/div/a/button")).submit();
'View positions' button is not clicking with the above code.What is happening in the web page?
You see the HTML for this page is
So, you can use the CSS selector for this as
WebDriver driver = new FirefoxDriver();
driver.get("https://www.ignitionone.com/company/careers/");
driver.manage().window().maximize();
Thread.sleep(2000);
driver.findElement(By.cssSelector("button.button.teal").click();
And then proceed with doing whatever is necessary. I executed with this in my Python code and it works fine.
Also, you will need to provide the Gecko executable path while calling for the FirefoxDriver()
The way I have done it before is to use the click handler.
driver.findElement(By.cssSelector(".profile-actions .primary_button > span")).click();
I'm sure you could also select the element by xpath rather than CSS in the above line. It's a similar question to this one.
I am using following xpath to click on element using JSExecutor in Selenium webdriver. This works fine in Firefox and chrome but does not work in IE.
Any idea to make this work? After lot of trial and error I have made this work in FF and chrome and have come up with the following XPath.
//*[contains(#class,'ui-select-choices-row') or contains(#id,'ui-select-choices-row')]//*[text()='TextofMyElementToBeclicked'
Additional info: This is a Jquery drop down on an angularJS application. When the user clicks on the drop down //ul is loaded and i am using the above xpath (which is part of //ul) to select the element based on text (using Javascript executor click). I used JS executor because, click() function in selenium simply could not click on the drop down element.
I am clicking element using below.
WebElement element = driver.findElement(By.xpath("YourNumbersXpath"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
enter code here
I successfully tested your XPath with IE11, so it's not an issue related to IE. It's most likely a timing issue. First click on the drop button, then wait for the targeted element to appear and finally click on it:
WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, 30);
driver.get("...");
// move the cursor to the menu Product
WebElement element = driver.findElement(By.xpath("drop down button")).click();
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("drop down item"))).click();
IE11 seems to struggle with contains(#class and possibly also the contains(#id. Try using alternative solutions like starts-with.
I am working on a sample assignment on Thomson Holidays website (http://www.thomson.co.uk/holidays.html). On left hand side there is a Holiday Search panel. I am unable to recognize any of these elements in WebDriver. However, in IDE these elements are recognized. Need more info on this as it is the first time i am experiencing such an issue. Below is the code sample:
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://www.thomson.co.uk/holidays.html");
driver.findElement(By.id("searchbutton")).click();
driver.findElement(By.id("holidayAttribute_1")).click();
driver.findElement(By.id("holidayAttribute_2")).click();
driver.findElement(By.id("holidayAttribute_3")).click();
Thread.sleep(5000);
Because they're in the iframe, you need switch to the iframe first.
Two lines added to your existing code as follows:
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://www.thomson.co.uk/holidays.html");
// optional, unnecessary in your case
// driver.switchTo().defaultContent(); // make sure outside of all iframes
// switch to search frame
WebElement searchFrame = driver.findElement(By.cssSelector("iframe[src='/thomson/page/byo/search/usp.page']"));
driver.switchTo().frame(searchFrame);
driver.findElement(By.id("searchbutton")).click();
driver.findElement(By.id("holidayAttribute_1")).click();
driver.findElement(By.id("holidayAttribute_2")).click();
driver.findElement(By.id("holidayAttribute_3")).click();
The search panel is inside an iframe. As the iframe is the first iframe, you can use the below code.
driver.get("http://www.thomson.co.uk/holidays.html");
// switch to search frame
driver.switchTo().frame(0);
driver.findElement(By.id("searchbutton")).click();
driver.findElement(By.id("holidayAttribute_1")).click();
driver.findElement(By.id("holidayAttribute_2")).click();
driver.findElement(By.id("holidayAttribute_3")).click();