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();
Related
I am trying to disable double clicking a Help label which is an anchor to open the Help window.
<p:a id="helpClick" onClick="help()">
<label value="Help" style="color:#FFFFFF;" />
</p:a>
When onClick() event is triggered once, either by Mouse click or Tapping the touchpad once, the help() method is being invoked.
void help() {
flag = true;
this.helpClick.setDisabled(true);
Window popupWindow = null;
popupWindow = (Window) Executions.createComponents("/zul/mainHelp.zul",
null, null);
this.popupWindow.setClosable(true);
popupWindow.addEventListener("onClose", new EventListener() {
void onEvent(Event event) throws Exception {
this.helpClick.setDisabled(false);
}
});
}
is the code which i added to handle the anchor tag with the id helpClick.
This is working perfectly fine when i use mouse clicks. For the first click, the window gets opened and simultaneously the Label is not taking any more click events.
When i try the same with mouse tap(using the touchpad), two single clicks are being triggered.
I have used onClick() to capture the event.
I am trying to disable the Label once it is clicked and the window is opened. Only after the window gets closed, i am enabling the label.
This is working totally fine when i use mouse clicks but not when i use tap.
With tapping, the label is taking multiple clicks which isnt the case with Mouse Click.
Without seeing code it's difficult to provide advice but maybe you can capture the onDoubleClick event and ignore it or forward it to the to the same listener as your onClick event.
... forward="onClick=onHelpClick,onDoubleClick=onHelpClick" ...
After question edit:
It sounds like a bug if you can double click a disabled component. One thing you could try is set your link to autodisable <p:a id="helpClick" onClick="help()" autodisable="self"> as per A component documentation
I am facing the below error!!
I am using Selenium WebDriver. Switching to a child window from parent and clicking a link on child, which redirects me to the earlier parent window with new url opened in it.
I need to switch to new Parent url in the same previous parent window but unable to do so.
any help much appreciated!!
Below is the code:
driver.findElement(By.id("href_billing_&_reporting")).click();
driver.findElement(By.linkText("Go to Billing Summary")).click();
driver.findElement(By.linkText("01 Mar 2016")).click();
Thread.sleep(5000);
driver.findElement(By.linkText("AMS TAX")).click();
driver.findElement(By.linkText("00842")).click();
String Parenthandel = driver.getWindowHandle();
for(String Child : driver.getWindowHandles()){
driver.switchTo().window(Child);
}
driver.switchTo().frame("modalSubWindow");
driver.findElement(By.linkText("View More Vehicle Details>>")).click();
driver.switchTo().window(Parenthandel);
I tried with defaultcontent() method too but no luck!!
Since the parent window is navigating to a new URL, selenium is refreshing the parent window handle.
Try this solution.
Save the child window handle
Get all window handles once again after clicking "View More Vehicle" link
Loop thru the handles and switch to the window which is not equal to child.
Using Collection (Set), can save all available open window details..
driver.findElement(By.linkText("Go to Billing Summary")).click();
driver.findElement(By.linkText("01 Mar 2016")).click();
Thread.sleep(5000);
driver.findElement(By.linkText("AMS TAX")).click();
driver.findElement(By.linkText("00842")).click();
Set<String> instancewindow= driver.getWindowHandles();
Iterator<String> it = instancewindow.iterator();
String parent =it.next();
String child = it.next();
driver.switchTo().window(child);
driver.switchTo().frame("modalSubWindow");
driver.findElement(By.linkText("View More Vehicle Details>>")).click();
driver.switchTo().window(parent);
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 have a modal popup that appears whenever an editor tries to save a component with some values (a date field in the past in this case).
In this popup I show the editor a few options (very similar to the default "Open Shared Item" dialog) and an OK/Cancel button combo. On Cancel I fire the "cancel" event and the editor goes back to the editing screen, all good here. On "OK" I want to change the value of the field to match whatever the editor selected, then save.
I tried to use an approach with FieldBuilder and the sample Boris mentioned on this other topic but I can't get to the field from my popup dialog.
Any suggestions on how I can go and modify the xml of the item (could be also a page) from a modal popup?
EDIT: Code used in getControlForFieldName
function getControlForFieldName(name) {
var fieldBuilder = $display.getView().properties.controls.fieldBuilder;
var fieldsContainer = fieldBuilder.properties.input;
var fieldsNode = fieldsContainer.getElement();
var fieldContainer = $dom.getFirstElementChild(fieldsNode);
while (fieldContainer) {
var labelNode = $dom.getFirstElementChild(fieldContainer);
var fieldNode = $dom.getNextElementSibling(labelNode);
var control = fieldNode.control;
if (control.getFieldName() == name) {
return control;
}
fieldContainer = $dom.getNextElementSibling(fieldContainer);
}
}
EDIT #2
After Frank's advice, and some help from Jaime & Frank offline, I got it to work as follows:
The popup is called from a Command Extension (Save & Close in my case)
The command.js specifies an event handler that gets called on "submit" (== OK was pressed)
$evt.addEventHandler(p.dialogPopup, "submit",
this.getDelegate(this._onPopupSubmit));
In my popup I am passing the selected item (it's a keyword ID) to the event handler:
this.fireEvent("submit", { id: select.options[select.selectedIndex].value });
and now back in the event handler _onPopupSubmit(e) I just read e.data.id, load this keyword, get properties like ID & Title, and update the metadata of the item using item.setMetadata("new metadata with updated values").
Simple :)
Your code runs in a popup, so any references you make to global variables will be taken from the popup window.
So when you get the fieldBuilder:
var fieldBuilder = $display.getView().properties.controls.fieldBuilder;
$display is a reference to a global variable. So this actually looks for the FieldBuilder in the popup window (which doesn't have one).
To get the FieldBuilder of the Component window, you can get it from the opener:
var fieldBuilder = opener.$display.getView().properties.controls.fieldBuilder;
You might want to consider actually passing the updated value to either a callback function or with a (custom) event though, since that makes your popup less dependent on opener. trick.
I created a list control at runtime as following:
var myList:List = new List();
ListArea.addChild(myList);
myList.percentHeight = myList.percentWidth = 100;
myList.itemRenderer = new ClassFactory (components.renderers.myRenderer);
myList.dataProvider = myDataArray;
myList.addEventListener(EVENT.CHANGE, historyBarClickHandler);
//Where myDataArray is an ArrayCollection consisting of my Custom ValueObjects.
When i execute the code it displays my list with custom item renderer, which is fine.
But when bring my mouse over it, it doesn't give any colour highlight which means it is not selecting.
Secondly, when i click on any of the list item, it doesn't dispatch any change event.
I tried a lot but couldn't understand it.
Please Guide
Thanks
Your itemRenderer may be causing another issue, but you're not listening for the correct event. It should be:
myList.addEventListener(ListEvent.CHANGE, historyBarClickHandler);