Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
avatar
vidya shree
Regular Participant
Regular Participant
Posts : 31
Join date : 2013-05-09

Unable to perform Actions on Mouse over Elements in Selenium WebDriver Empty Unable to perform Actions on Mouse over Elements in Selenium WebDriver

Wed Jun 05, 2013 9:15 pm
Hi

There is an invisible element on my HTML page which becomes visible when a mouse hover is done on the element. What I Have to do is


  1. Hover over the element
  2. Click on the element (it will display 5 options)
  3. Click on one of the options

Here i am able to locate one of the option by using Xpath but unable to do action on it viz. Click, sendkeys(Keys.Enter) etc..

Please help to perform action on that selected items.

Thanks in Advance,

Vidya
avatar
tarun3kumar
Master
Master
Posts : 186
Join date : 2012-02-14
http://seleniumtests.com

Unable to perform Actions on Mouse over Elements in Selenium WebDriver Empty Re: Unable to perform Actions on Mouse over Elements in Selenium WebDriver

Thu Jun 06, 2013 10:12 am
You may have to construct web element object for the elements which appear after hover. Once you get the element you should be able to click on it using WebDriver,
avatar
vidya shree
Regular Participant
Regular Participant
Posts : 31
Join date : 2013-05-09

Unable to perform Actions on Mouse over Elements in Selenium WebDriver Empty Re: Unable to perform Actions on Mouse over Elements in Selenium WebDriver

Thu Jun 06, 2013 1:07 pm
Tarun,

Thanks for ur response.
"You may have to construct web element object for the elements which appear after hover"--->I din get u exactly,But tried something (How i understood) and attached my script for ur reference.

In the below script ,I tried to locate an element "Language",which becomes visible when a mouse hover is done on the element "CB connection".And I have to click on 'Language'.
I have tried in different ways.I cudnt do the action "Click" on that element.But able to locate the element.

URL:http://www.joomlapolis.com/forum/42-usability/61928-mouse-over-on-registration-form-tooltip

Here is my sample script

Code:
import java.util.List;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;


public class TestPrgm {
 public static void main(String[] args) throws InterruptedException{
  WebDriver driver=new FirefoxDriver();
  driver.get("[url=http://www.joomlapolis.com/forum/42-usability/61928-mouse-over-on-registration-form-tooltip]http://www.joomlapolis.com/forum/42-usability/61928-mouse-over-on-registration-form-tooltip[/url]");
 
  Actions builder = new Actions(driver);
  Action mouseOverCBconnection = builder
  .moveToElement(driver.findElement(By.xpath("//html/body/div/div[3]/div/div/div/ul/li[4]/a/span")))
  .build();

  mouseOverHome.perform();

  Thread.sleep(2000);

  WebElement elt=driver.findElement(By.xpath("//html/body/div/div[3]/div/div/div/ul/li[4]/ul/li[2]"));
  Action mouseOverHome1 = builder
    .moveToElement(elt)
    .click(elt)
    .build();
 
  mouseOverHome1.perform();
 
  /*if("Languages".equals(driver.findElement(By.xpath("//html/body/div/div[3]/div/div/div/ul/li[4]/ul/li[2]")).getText())) {
      if(elt.isEnabled() && elt.isDisplayed())
          elt.sendKeys(Keys.ENTER);
  }*/
 
 
 
  // I ve tried this too

  /*String txt=driver.findElement(By.xpath("//html/body/div/div[3]/div/div/div/ul/li[4]/ul/li[2]")).getText();
  driver.findElement(By.xpath("//html/body/div/div[3]/div/div/div/ul/li[4]/ul/li[2]")).click();
  http://driver.findElement(By.className("item156")).click();  ------>Tried to locate the same element by classname
  System.out.println(txt);*/

  Thread.sleep(2000);
 
  driver.close();
    }

 }

Please help.

Thanks,

Vidya
avatar
vidya shree
Regular Participant
Regular Participant
Posts : 31
Join date : 2013-05-09

Unable to perform Actions on Mouse over Elements in Selenium WebDriver Empty Re: Unable to perform Actions on Mouse over Elements in Selenium WebDriver

Thu Jun 06, 2013 8:54 pm
Tarun,

FYI.

I came across tis link:

http://selenium-testng.com/webdriver-events/

Please refer this. I tried the methods given here (xcept last one),but still i was unable to do the Action (Click) on the Element.

Thanks,

Vidya
avatar
mail2prassad
Amateur
Amateur
Posts : 41
Join date : 2013-06-05

Unable to perform Actions on Mouse over Elements in Selenium WebDriver Empty Re: Unable to perform Actions on Mouse over Elements in Selenium WebDriver

Thu Jun 06, 2013 9:38 pm
replace your block of code

if("Languages".equals(driver.findElement(By.xpath("//html/body/div/div[3]/div/div/div/ul/li[4]/ul/li[2]")).getText())) {
if(elt.isEnabled() && elt.isDisplayed())
elt.sendKeys(Keys.ENTER);
}

with the following block of code and try
WebElement languageElem = driver.findElement(By.xpath("//a[@href='/cb-solutions/languages']"));
if(languageElem.isDisplayed())
languageElem.click();
avatar
vidya shree
Regular Participant
Regular Participant
Posts : 31
Join date : 2013-05-09

Unable to perform Actions on Mouse over Elements in Selenium WebDriver Empty Re: Unable to perform Actions on Mouse over Elements in Selenium WebDriver

Fri Jun 07, 2013 12:43 pm
Prassad,

Thank u so much. Its working perfectly now.

But still have few doubts…

· “WebElement languageElem = driver.findElement(By.xpath("//a[@href='/cb-solutions/languages']"));
if(languageElem.isDisplayed())
languageElem.click();”


In the above code if I replaced the xpath by “//html/body/div/div[3]/div/div/div/ul/li[3]/ul/li[2]”,which is the absolute xpath for “Language”,I am not able to do the “Click” action.

Why so??.But by using that I am able to locate the “Language”.I checked tat by using following script

String txt=driver.findElement(By.xpath//html/body/div/div[3]/div/div/div/ul/li[3]/ul/li[2]”)).getText();

System.out.println(txt);”

Output:

Language

· How to get all the options which all visible when mouse hover is done ??

For example:

In the same Scenario, I want to capture/read all the options under CB connection once mouse hover is done (i.e Languages, Adds on ,Incubator,etc..).

Note: Actually I need to read all the options as how we do for Dropdown box elements.



Please guide me.

Thanks,

Vidya
avatar
vidya shree
Regular Participant
Regular Participant
Posts : 31
Join date : 2013-05-09

Unable to perform Actions on Mouse over Elements in Selenium WebDriver Empty Re: Unable to perform Actions on Mouse over Elements in Selenium WebDriver

Fri Jun 07, 2013 1:00 pm
Just now noticed that all my approaches working perfectly now with the replacement of xpath"//a[@href='/cb-solutions/languages']" instead Of “//html/body/div/div[3]/div/div/div/ul/li[3]/ul/li[2]”.

Now my query is Why I am not able to do the action by using Absolute xpath ??

Note: I got that absolute xpath by using FireBug only.

Vidya.
avatar
mail2prassad
Amateur
Amateur
Posts : 41
Join date : 2013-06-05

Unable to perform Actions on Mouse over Elements in Selenium WebDriver Empty Re: Unable to perform Actions on Mouse over Elements in Selenium WebDriver

Fri Jun 07, 2013 4:55 pm
If you look at the source, "//html/body/div/div[3]/div/div/div/ul/li[3]/ul/li[2]” is not a clickable element. There is an anchor tag inside this element which is clickable. That is the reason you can't click on the element.
avatar
vidya shree
Regular Participant
Regular Participant
Posts : 31
Join date : 2013-05-09

Unable to perform Actions on Mouse over Elements in Selenium WebDriver Empty Re: Unable to perform Actions on Mouse over Elements in Selenium WebDriver

Fri Jun 07, 2013 5:06 pm
Prassad,

Thanks for ur response.I have another query

How to get all the options which all visible when mouse hover is done ??

For example:


In the same Scenario, I want to capture/read all the options under CB connection once mouse hover is done (i.e Languages, Adds on ,Incubator,etc..).

Note: Actually I need to read all the options as how we do for Dropdown box elements.
avatar
mail2prassad
Amateur
Amateur
Posts : 41
Join date : 2013-06-05

Unable to perform Actions on Mouse over Elements in Selenium WebDriver Empty Re: Unable to perform Actions on Mouse over Elements in Selenium WebDriver

Fri Jun 07, 2013 9:02 pm
After mouse hover try the following block of code.
Code:

WebElement CBsolutionsElement = driver.findElement(By.xpath("//a[@href = '/cb-solutions']"));
  List<WebElement> dropdownElements = CBsolutionsElement.findElements(By.xpath("//a[contains(@href, '/cb-solutions/')]"));
 
  for(WebElement element : dropdownElements){
     System.out.println(element.getText());
  }
avatar
vidya shree
Regular Participant
Regular Participant
Posts : 31
Join date : 2013-05-09

Unable to perform Actions on Mouse over Elements in Selenium WebDriver Empty Re: Unable to perform Actions on Mouse over Elements in Selenium WebDriver

Mon Jun 10, 2013 1:34 pm
Thank u Prassad.

Its working (though i am getting some extra options), I came to known about the "contains n starts-with" Xpath patterns.

Thanks again,

Vidya
Sponsored content

Unable to perform Actions on Mouse over Elements in Selenium WebDriver Empty Re: Unable to perform Actions on Mouse over Elements in Selenium WebDriver

Back to top
Permissions in this forum:
You cannot reply to topics in this forum