Xpath is not working on MouseOver(CatMenu) in Selenium - selenium

There is problem about selenium for all web driver which cannot open mouseover menu.Altough assing to Xpath of element web driver cannot open Mouse Over (CatMenu) and log is that "Must provide a location for a move action".
i want to go n11.com web adress and over on Kitap, Müzik, Film, Oyun and click Kitap but its not working.
Thank you
#Test
public void startWebDriver(){
System.setProperty("webdriver.chrome.driver", "C://chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://www.n11.com");
Actions act = new Actions(driver);
act.moveToElement(driver.findElement(By.xpath(".//*[#id='contentMain']/div/nav/ul/li[8]/a"))).perform();
}

Use following code to achieve the same -
System.setProperty("webdriver.chrome.driver", "C://chromedriver.exe");
driver =new ChromeDriver();
driver.get("http://www.n11.com/");
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
WebElement menu = driver.findElement(By.xpath("//li[#class='catMenuItem']/a[#title='Kitap, Müzik, Film, Oyun']"));
WebElement submenu = driver.findElement(By.xpath("//li[#class='subCatMenuItem']/a[#title='Kitap']"));
Actions action = new Actions(driver);
action.moveToElement(menu).moveToElement(submenu).click().build().perform();
Use some Implicit Wait to avoid timeout exceptions to find your web element
Use more specific xpath to find your web element.
In your case first you need to hover on Kitap, Müzik, Film, Oyun menu and then have to perform click on Kitap submenu

You can try to use ExplicitWait with more specific XPath:
WebDriverWait wait = new WebDriverWait(driver, 15);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("(//a[#title='Kitap, Müzik, Film, Oyun']")[2])));
// WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Kitap, Müzik, Film, Oyun")));
Actions act = new Actions(driver);
act.moveToElement(element).perform();

Related

Selenium webdriver wait element and click

InternetExplorerDriver driver = new InternetExplorerDriver();
driver.get("http://www.wiki-doctor.com");
WebElement element = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.elementToBeClickable(By.id("btnSearch")));
element.click();
it waits for the element btnSearch to be displayed and click on it, however, it doesn' t seems to do anything, do you have any idea why it happens ?
Thanks
This adds United States as a locale, and then waits until a picture of the doctor is displayed.
driver.get("http://www.wiki-doctor.com");
//Enter united states into field
driver.findElement(By.id("field-findDoctor-town")).sendKeys("United States");
WebElement element = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.elementToBeClickable(By.id("btnSearch")));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
WebDriverWait wait = new WebDriverWait(driver,10);
//Wait for picture of doctor
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#dvparcticianlist > div.row > div > div.listing-row > div.doc-photo-container")));
System.out.println("Search Successful");
}
Once the page is loaded, first we need to wait for the intended WebElement i.e. the first Search Box to be clickable. Then we will send some text to both the Search Boxes and then invoke click() method on the Search Button as follows :
System.setProperty("webdriver.ie.driver", "C:\\Utility\\BrowserDrivers\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get("http://www.wiki-doctor.com");
WebElement locality = (new WebDriverWait(driver, 5))
.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[#id='field-findDoctor-town']")));
locality.sendKeys("Pune");
driver.findElement(By.xpath("//input[#id='speciality']")).sendKeys("Doctor");
driver.findElement(By.xpath("//button[#id='btnSearch']")).click();
WebDriverWait wait =new WebDriverWait(driver, 90);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("xpath")));
driver.findElement(By.xpath("xpath")).click();

while automating the slider, The slider moves only when i placed my mouse over it in selenium

http://automationpractice.com/index.php?id_category=5&controller=category#/
This is my code,whats wrong with it?
By locator = By.cssSelector(".ui-slider-handle.ui-state-default.ui-corner-all.ui-state-hover");
wait.until(ExpectedConditions.presenceOfElementLocated(locator));
wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
WebElement sliderRight = driver.findElement(locator);
action.dragAndDropBy(sliderRight,-40,0).build().perform();
action.moveToElement(sliderRight).click().build().perform();
Where's actions taking under consideration the driver.
Try to enter the following code,
Actions action=new Actions(WebDriver);
You have used a wrong cssSelector. I have modified your code and it should work now.
Here is the java code
System.setProperty("webdriver.chrome.driver", "src/chromedriver 3");
WebDriver driver = new ChromeDriver();
driver.get("http://automationpractice.com/index.php?id_category=5&controller=category#/");
Actions action = new Actions(driver);
WebDriverWait wait = new WebDriverWait(driver, 30);
//modified the css selector
By locator = By.cssSelector(".ui-slider-handle.ui-state-default.ui-corner-all");
wait.until(ExpectedConditions.presenceOfElementLocated(locator));
wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
WebElement sliderRight = driver.findElement(locator);
action.dragAndDropBy(sliderRight,70,0).build().perform();
action.moveToElement(sliderRight).click().build().perform();

mouse hover in not working in IE 10 with webdriver need to click on multiple submenus

need to mouse hover on menu first >menu then >submenu1 then >submenu1 then > submenu1
>
System.setProperty("webdriver.ie.driver","E:\workplace\AutomationTemplateWrking1\src\resource\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.get("example.com/");
driver.findElement(By.id("user_login")).sendKeys("pmtest");
driver.findElement(By.id("user_password")).sendKeys("#123");
driver.findElement(By.className("login-button")).click();
driver.manage().window().maximize();
WebElement ele1=driver.findElement(By.id("menu"));
WebElement ele2=driver.findElement(By.xpath("//div[#class='head-fixed']/div/div/div/ul/li/ul/li/a[text()='Administration']"));
WebElement ele3=driver.findElement(By.xpath("(//a[text()='Charge Codes'])[1]"));
WebElement ele4=driver.findElement(By.xpath("(//a[text()='Charge Codes'])[2]"));
Actions a1 = new Actions(driver);
a1.moveToElement(ele1).build().perform();
Thread.sleep(1000);
a1.moveToElement(ele2).build().perform();
Thread.sleep(1000);
a1.moveToElement(ele3).build().perform();
Thread.sleep(1000);
ele4.click();
solution:
For me it worked with 64bit version of IEDriverServer. I added the property requireWindowFocus with "true" value: But Not able to perform on mousehovers error:stacktrace information is not available

Unable to click a value from a sub list of the main list using mouse over action of selenium webdriver

I am trying to automate a scenario where I can select a value from a sub-menu present under main menu.
Below is the application url:
http://www.jetairways.com/EN/IN/Home.aspx
Its a mouser over functionality and tried to automate the Tab (Plan your travel-> Flights -> Book Online) with the below code but not working:
WebElement we = driver.findElement(By.xpath(".//*[#id='PlanYourTravel']/span/b"));
WebElement we1 = driver.findElement(By.xpath(".//*[#id='lnkThirdLevel58']"));
WebElement we2 = driver.findElement(By.xpath(".//*[#id='ddsubSubmenu58']/li[1]/a"));
Actions builder = new Actions(driver);
WebDriverWait wait = new WebDriverWait(driver, 15, 100);
builder.moveToElement(we).perform();
Thread.sleep(10000);
wait.until(ExpectedConditions.visibilityOf(we1));
builder.moveToElement(we1).perform();
wait.until(ExpectedConditions.visibilityOf(we2));
builder.moveToElement(we2).click().perform();
I am getting the element not visible issue. Quick help on this would be much appreciated.
I have tried with below code to click on "Book Online" and its working fine
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
driver.get("http://www.jetairways.com/EN/IN/Home.aspx");
Actions actObj = new Actions(driver);
//actObj.moveToElement(driver.findElement(By.xpath("//*[text()='Plan Your Travel']"))
actObj.moveToElement(driver.findElement(By.xpath("//*[#id='PlanYourTravel']/span/b"))).perform();
actObj.moveToElement(driver.findElement(By.xpath("//li[#title='Flights']/a"))).perform();
driver.findElement(By.xpath("//a[#title='Book Online']")).click();

Select a text and perform a click action

I'd like to select some text and perform a click action - like in Winword where we click Bold after selecting some text...
I have to select the text and click on the <B> bold icon in the textarea.
Any idea on how to do this using Selenium/Webdriver?
In Java, The Advanced User Interactions API has your answer.
// the element containing the text
WebElement element = driver.findElement(By.id("text"));
// assuming driver is a well behaving WebDriver
Actions actions = new Actions(driver);
// and some variation of this:
actions.moveToElement(element, 10, 5)
.clickAndHold()
.moveByOffset(30, 0)
.release()
.perform();
I tried with Action builder and played with offset. It worked for me.
Actions action = new Actions(driver);
action.moveToElement(wblmt,3,3).click().keyDown(Keys.SHIFT).moveToElement(wblmt,200, 0).click().keyUp(Keys.SHIFT).build().perform();
I tried this way and it did not work. Here are the codes:
System.setProperty("webdriver.chrome.driver", "D:/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com.vn");
driver.manage().window().maximize();
WebElement text = driver.findElement(By.xpath("//*[contains(text(),'Google.com.vn')]"));
Actions actions = new Actions(driver);
actions.moveToElement(text, 10, 5).clickAndHold().moveByOffset(30, 0).release().perform();
I switched to JavascriptExecutor and it worked:
System.setProperty("webdriver.chrome.driver", "D:/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com.vn");
driver.manage().window().maximize();
WebElement text = driver.findElement(By.xpath("//*[contains(text(),'Google.com.vn')]"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].setAttribute('style', 'background: blue;');", text);