I have a problem closing a Fancybox using selenium Webdriver. On the fancy-box is a big "X" located for closing it[http://tinypic.com/r/2w3xq1f/8].
I tried this but without success:
driver.findElement(By.className("fancybox-item fancybox-close")).click();
driver.findElement(By.xpath("html/body/div[3]/div/a")).click();
PS: Please see snapshot
Use the correct XPATH selector
e.g.
`driver.findElement(By.xpath('//a[#class="fancybox-item fancybox-close"]')).click();`
For more information, look at: http://www.w3schools.com/xpath/xpath_syntax.asp
Use the below code to wait 10 seconds for the visibility of 'Close' element and then clicking on it to close:
try{
WebElement element = new WebDriverWait(driver,10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[#title='Close']")));
element.click();
}catch(Throwable e){
System.err.println("Element wasn't found: "+e.getMessage());
}
Maybe it is in new frame, try driver.switchTo().frame
Related
As per the above code, I have tried to locate and perform action on elements in Selenium.
Actions action = new Actions(driver);
Putting Control to Elements
WebElement we = driver.findElement(By.xpath("//li[#class='static dynamic-children']/a[#href='/activa/gentex/ee/#']/span[#class='additional-background']"));
action.moveToElement(we).build().perform();
WebDriverWait wait = new WebDriverWait(driver, 50);
// wait for the edit employee information to appear
wait.until(ExpectedConditions.presenceOfElementLocated(By
.xpath("//a[contains(#class,'selected')]/span[#class='additional-background']/span[#class='menu-item-text']")));
// action.moveToElement(driver.findElement(By.xpath("//div[#id='zz1_TopNavigationMenuV4']/div/ul/li/ul/li/ul/li[2]/a/span/span"))).build().perform();
// action.click(driver.findElement(By.xpath("//div[#id='zz1_TopNavigationMenuV4']/div/ul/li/ul/li/ul/li[2]/a/span/span"))).perform();
Moving control to Child menu item to click on it.
driver.findElement(By.xpath("//a[contains(#class,'selected')]/span[#class='additional-background']/span[#class='menu-item-text']")).click();
It seems you have incorrect xpath , Please check correct code below :
Actions action = new Actions(driver);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
WebElement Mainmenu= driver.findElement(By.xpath("//*[#id='zz1_TopNavigationMenuV4']/div/ul/li/ul/li[1]"));
action.moveToElement(Mainmenu).build().perform();
WebElement submenu1 = driver.findElement(By.xpath("//*[#id='zz1_TopNavigationMenuV4']/div/ul/li/ul/li[1]/ul/li[1]/a/span/span"));
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[#id='zz1_TopNavigationMenuV4']/div/ul/li/ul/li[1]/ul/li[1]/a/span/span")));
submenu1.click();
I am hovering mouse on main menu : My Benefit Resources and then clicking on child menu : Enrollment. Above code should work fine for you.
For reading the tags try this :
<span>xyz</span>
You can try this:
re-frame the xpath as
//span[contains(.,'xyz')]
It should help.
I want to check if there is a clickable image present in the table cell.
If(clickable image present)
{
//
}
else
{
//
}
How do I do it in webdriver using Java?
Does your image tag have a name or id associated with it ?? Please post some code to help us help you.
in that case use
WebElement image = driver.findElement(By.name("imagename"));
image.click();
or
WebElement image = driver.findElement(By.id("imageid"));
image.click();
This identification can be done on name,id,class,xpath etc.
If not you may have to use xpath or css selectors
WebElement image = driver.findElement(By.xpath("xpath"));
image.click();
You can check if the image is clickable by using
WebDriverWait wait = new WebDriverWait(yourWebDriver, 5);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//xpath_to_element"));
and then perform element.click().
EDIT:
okay, i have checked the code and its rendering out by a jquery widget.
END
I am trying to move the cursor to <a \>, but the problem is that the element is not rendered until i move mouse pointer physically on selected image.
How can i move to the mouse to hover over <a \> to select/click?
FF version 20
Selenium WebDriver version: 2.31.2.0
Current code
Actions actions = new Actions(driver);
int locationX = Convert.ToInt32(ratingElementDiv[i].Location.X);
int locationY = ratingElementDiv[i].Location.Y;
actions.MoveToElement(WaitForElement(By.CssSelector(starElement)), locationX, locationY).Click().Perform();
i dont see any action happening... any help?
Action is composed by 3 steps.
configuration
Actions builder = new Actions(driver);
Point location ratingElementDiv[i].getLocation();
builder.MoveToElement(WaitForElement(By.CssSelector(starElement)), location.X, location.Y).click();
(i'm not sure about the click)
get the action
Action selectLink = builder.build();
execution
selectLink.perform();
try this and tell me if you still have some problem.
This link will help you. It explain both keyboard and mouse event.
http://www.guru99.com/keyboard-mouse-events-files-webdriver.html
Lets say when you click "Select Your Test" you see a dropdown of multiple elements(ABC, DEF, GHI, etc ). You want to select ABC and click it. Use following.
driver.findElement(By.linkText("Select Your Test")).click();
new Actions(driver).moveToElement(driver.findElement(By.linkText("ABC"))).click().perform();
it works to me
//定位一個按鈕
WebElement button = driver.findElement(By.xpath("//div[#class='page-button']"));
//new 一個移動滑鼠的物件
Actions clickAction = new Actions(driver).click(button);
//執行
clickAction.build().perform();
HTML
<input class="button" type="button" onclick="$.reload('results')" value="Search">
I don't have an id or name for this . Hence am writing
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://....");
driver.findElement(By.cssSelector("input[value=Search]")).click();
But click() is not happening.
Tried
driver.findElement(By.cssSelector(".button[value=Search]")).click();
Tried
value='Search' (single quotes).
these Selectors are working in
.button[value=Search] {
padding: 10px;
}
input[value=Search] {
padding: 10px;
}
i would inject piece of js to be confident in resolving this issue:
first of all locate element using DOM (verify in firebug):
public void jsClick(){
JavascriptExecutor js = (JavascriptExecutor) driver;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("document.getElementsByTagName('button')[0].click();");
js.executeScript(stringBuilder.toString());
}
jsClick();
from the retrospective of your element it be like:
....
stringBuilder.append("document.getElementsByTagName('input')[0].click();");
....
Please, note: document.getElementsByTagName('input') returns you an array of DOM elements. And indexing it properly e.g. document.getElementsByTagName('input')[0], document.getElementsByTagName('input')1, document.getElementsByTagName('input')[2]....
,etc you will be able to locate your element.
Hope this helps you.
Regards.
Please use the below code.
driver.findElement(By.cssSelector("input[value=\"Search\"]")).click();
It works for me. And make sure that the name is "Search", coz it is case sensitive.
Thanks
Are you sure that using this CSS-selector (input[value=Search]) on your page you have only one result?
single quotes are missing in your code, the [value=Search] should be replaced with [value='Search'].
first you have to check if the selector u are using will work or not..
If you are using chrome or FF,you can follow these steps,
go to the page where button (to be clicked) is present,
open web console and type in the following and click enter..
$("input[value='Search']")
or
$("input[value='Search'][type='button']")
or
$("input[value='Search'][type='button'].button")
you will get a list of elements which can be accessed using this selector, if that list contains only one element (button that you want to click), then this selector is valid for your use..otherwise u'l have to try some other selector..
If any of the above selector is valid,u'l have to change your code accordingly..
driver.findElement(By.cssSelector("input[value='Search'][type='button'].button")).click();
I'm using following code to open thickbox for dynamically generated anchor tags, but it doesn't work for the first time, but second time it works.
function createMarker(point, InnerAddress) {
//Other Code
var strFBUserID = new GMarker(point, markerOptions);
GEvent.addListener(strFBUserID, "click", function() {
strFBUserID.openInfoWindowHtml(InnerAddress.split('$$')[0]);
tb_init('a.gmapthickbox');//works second time
});
allmarkers.push(strFBUserID);
return strFBUserID;
}
It seems tb_init fires before, openInfoWindowHtml, any way to solve this issue? I tried setTimeOut but no success. Any help will be greatly appreciated.
Try listening to the infowindowopen event on your map instance before calling tb_init. It should be fired once the content is ready in the DOM.
http://code.google.com/apis/maps/documentation/javascript/v2/reference.html#GMap2.infowindowopen