Mouse hovering not happening in selenium with JAVA - hover

Mouse hovering not happening on both chrome and FF.
Below is the code I have used.
Can anybody help me.
//WebDriver driver = new FirefoxDriver();
//driver.get("http://demo.pickframes.com");
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Chrome Driver\\chromedriver.exe");
ChromeDriver driver= new ChromeDriver();
Actions builder=new Actions(driver);
driver.get("http://demo.pickframes.com");
Thread.sleep(6000);
WebElement shop=driver.findElement(By.linkText("SHOP"));
builder.moveToElement(shop).perform();
Thread.sleep(2000);
driver.findElement(By.linkText("CANVAS")).click();

Related

Selenium cannot find element

Having some issues using Selenium web driver in Chrome.
My goal is to give the user ~15-30 seconds to log in on there own and then start doing automated testing.
The problem is after I click the login button and go to the next page, I am not able to find elements by xpath, id, etc.
public static void runTest() throws InterruptedException {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("http://www.url.com");
driver.manage().window().maximize();
Thread.sleep(15000);
driver.findElement(By.xpath("//*[#id=\"content-main\"]/div/div/form/div/p/input")).click();
System.out.println("User has logged in and it has found element for Attachment Upload.");
Thread.sleep(15000);
driver.findElement(By.xpath("//*[#id=\"invoiceMenu\"]/a")).click();
}
I have also tried using explicit waits and have had no luck for example:
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(
ExpectedConditions.visibilityOfElementLocated(By.id("someid")));
The error I am usually getting back is:
Exception in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.xpath: //*[#id="invoiceMenu"]/a (tried for 10 second(s) with 500 milliseconds interval)
Edit:
Was able to get some of the elements (angular ones) working with a few plugins for Chrome. Element Locator and ChroPath worked fantastic. Took some playing around with, but once I got one I was able to piece together the rest of them.
I would suggest that you open the chrome console on your browser and try to interact with the element in question e.g. using:
document.getElementById('someId').click()
If you are able to click on the element like that, then you can use javascript executor in your code as follows:
((JavascriptExecutor)driver).executeScript("document.getElementById('someId').click();");

SendKeys(Keys.Tab) does not work on Chrome Version 53.0.2785.116

Today I observed that SendKeys(Keys.Tab) does not working on Chrome webdriver. However it works perfectly on IE and FireFox. Other than Tab, i tried few other keys like Space, Backspace, Clear, some text, Enter etc working as expected on Chrome.
for example:
private IWebDriver driver;
private string baseURL;
driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://accounts.google.com/SignUp?");
driver.FindElement(By.Id("FirstName")).Clear();
driver.FindElement(By.Id("FirstName")).SendKeys(Keys.Tab);
Anybody know why, Keys.Tab won't working on latest Chrome Version 53.0.2785.116?
OS: Windows 7 Service Pack 1
The cursor suppose to move/focus to Last name text field
try to add code below at the end of your code:
var element = driver.FindElement(By.Id("FirstName"));
if (!element.Equals(driver.SwitchTo().ActiveElement())) return;
var js = (IJavaScriptExecutor)driver;
js.ExecuteScript("arguments[0].blur();", element);
It means if the cursor still focus on current element, trigger blur function to move to next element.

I am trying to automate a HTML5 video in selenium webdriver with C#

Video doesnt have specific ID, its from youtube. I have tried it using javascript excecutor but not working. the link is :
http://www.myhomepay.com/Tour/Nanny-Tax-Guide
Hi Parvathy please try it like below it will play the player. only catch here is why its not playing is because its inside the iframe and to perform an operation inside a specific iframe first we have to identify that iframe and then move to that iframe to perform action with webdriver
Hi i am a java guy so posting answer in java
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.myhomepay.com/Tour/Nanny-Tax-Guide");
driver.manage().window().maximize();
// first identify the play button over the youtube video player
// Please note youtube palyer is inside the iframe hence first we have
// to identify and then switch to the i fame
List<WebElement> iframe = driver.findElements(By.tagName("iframe"));
System.out.println("Total iframe on the webpage is : "+ iframe.size());
driver.switchTo().frame(iframe.get(0));
driver.findElement(By.cssSelector(".ytp-large-play-button.ytp-button")).click();
}
UPDATE : for C# you can do it like below
iFrameElement = Driver.FindElementByTagName("iFrame");
driver = Driver.SwitchTo().Frame(this.iFrameElement);
driver.FindElement(selector);
please refactor code as per C#.hope this helps

Element not clickable using Selenium webdriver with Chrome (same code:works fine using firefox)

Using selenium-2.44.tar.gz and chrome for automating test cases:Very strange my code works fine using Firefox 33 but fails using Google Chrome:
"WebDriverException: Message: u'unknown error: Element is not
clickable at point(57, 161). Other element would receive the click: ...\n
(Session info: chrome=42.0.2311.135 )\n (Driver info:
chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64)'"
self.driver.find_element_by_xpath(".//[#id='searchMessagstoryBtn']").click()
any idea? shouldnt it work better with chrome one wonders since webdriver is Google code nowdays or am I wrong!!!
Unlike firefox, to use chromedriver you have to download chromedriver from http://www.seleniumhq.org/download/ and had to give path in your code.
You can use the below code, to use chrome driver in java or in python
Java:
public void testGoogleSearch() {
// Optional, if not specified, WebDriver will search your path for chromedriver.
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com/xhtml");
Thread.sleep(5000); // Let the user actually see something!
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("ChromeDriver");
searchBox.submit();
Thread.sleep(5000); // Let the user actually see something!
driver.quit();
}
Python:
import time
from selenium import webdriver
driver = webdriver.Chrome('/path/to/chromedriver') # Optional argument, if not specified will search path.
driver.get('http://www.google.com/xhtml');
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5) # Let the user actually see something!
driver.quit()
It seems to be a bug in ChromeDriver.
http://code.google.com/p/selenium/issues/detail?id=2766
Try this workaround solution from form #27. I hope it would help you:
I ran into this same issue as well with Chrome...clicking the element
works fine in firefox but not in Chrome...the fix is pretty easy
though, all you have to do is scroll the element into view before
clicking it, and you won't run into this problem in Chrome. Here's the
code i use:
IWebElement elementToClick = ;
// Scroll the browser to the element's Y position (driver as
IJavaScriptExecutor).ExecuteScript(string.Format("window.scrollTo(0,
{0});", elementToClick.Location.Y));
// Click the element elementToClick.Click();
Hope this helps anyone else who runs into this issue
#FindBy(xpath = "//[#id='searchMessagstoryBtn']")
private WebElement Search_btn;
public WebElement getSearchBtnClick() {
return Search_btn;
}
public void Click_Search_Btn() {
//click the search button
TimeUnit.SECONDS.sleep(3);
getSearchBtnClick().click();
}

Selenium WebDriver not working for Html5 drag and drop

Below is the code I am using, it will access one public website which is written using Html5,the code is trying to drag the "One" to trashbin, but it doesn't do anything. Is there any workaround to make it work? Thanks in advance!
FirefoxProfile profile = new FirefoxProfile();
profile.setEnableNativeEvents(true);
WebDriver driver = new FirefoxDriver(profile);
driver.get("http://html5demos.com/drag");
WebElement draggable = driver.findElement(By.id("one"));
WebElement droppable = driver.findElement(By.id("bin"));
new Actions(driver).dragAndDrop(draggable, droppable).build().perform();
Additional information is:
Selenium version: 2.25.0
OS: Mac OS Lion
Browser: Firefox
Browser version: 10.0.2 and 14.0.1
I would risk saying it is some sort of compatibility issue. I used the following code on http://jqueryui.com/demos/draggable/
System.setProperty("webdriver.ie.driver","C:\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get("http://jqueryui.com/demos/draggable/");
WebElement draggable = driver.findElement(By.id("draggable"));
new Actions(driver).dragAndDropBy(draggable, 200, 10).build().perform();
and it worked like a charm on the IE9. However it did not work with my Firefox 14 which may be to "new".
You can also try some workaround using JavaScriptExecutor, sth like this is described here: HTML5 Drag and Drop using Selenium Webdriver for Ruby