I can't for the life of me figure out what is going on. the code is simple:
//WebDriver driver = new InternetExplorerDriver();
//WebDriver driver = new FirefoxDriver();
driver.get("http://www.yahoo.com");
driver.findElement(By.xpath("//*[@id='pa-u_14782488-bd']/a/span[2]")).click();
I use either ff or ie driver. but last 2 line of code is same. works for ie, but not ff. funny thing is i'm getting the xpath from ff firebug so xpath is correct for ff. ff version 7.0.1. Its just the Mail link on the left column of yahoos site. Why is this so hard?
Up to Selenium 2.53 versions, Firefox was the native browser for Selenium WebDriver and the user did not have to download any additional package or driver executable for launching Firefox browser. But, from Selenium 3.0, you need to download the Gecko driver which will interact with the Firefox browser.
Selenium WebDriver provides two different identifiers to interact with links. linktext () identifier matches exact text associated with the link web element. So, to click on above-mentioned link code will be: partialLinktext () identifier matches partial text associated with the link web element. It can be considered as a contains method.
I think selenium is sending the click but browser (IE/FF/chrome) are not ready to process it. May be its binding to JS is not done or something like that.
Step 1: Navigate to the official Selenium website. Under third-party drivers, one will find all the drivers. Just click on the Mozilla GeckoDriver documentation as shown below. Step 2: After that, check the latest supported platforms of GeckoDriver versions in the documentation and click on GeckoDriver releases as shown below:
As Slanec mentioned these kind of sites use dynamic id's,so a better option in the above specified case would be to use "title" attribute,which has lesser probability of changing.. if you want to go with xpath,this will work,
driver.findElement(By.xpath("//*[@title='Mail']")).click();
Even better option will be to use link text,because it works the same way as the user manually would click...
driver.findElement(By.linkText("MAIL")).click();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With