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);
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'm using DX 15.1, and I'm trying to create a new tab from a child form.
So, basically, I have a parent form called "pForm", and a child form called "cForm".
I'm using DocumentManager module and switched it to TabbedView mode.
When I'm trying to create a new tab from pForm, it's totally fine.
the problem is, when I'm can't create a new tab from cForm into pForm's TabbedView.
How do I achieve this?
Thanks, mate :)
UPDATE :
#DmitryG, thanks for your response.
I've attached a screenshot below.
The MDI-Parent is the RGP page with a settings header. and the MDI-Child is the Class Attendance form (popped-up window, triggered by a button inside the RGP form).
Can you give a solution, how to make the Class Attendance Form (mdi-child) became a new Tab beside RGP tab when it's triggered by a button within mdi-parent? Not as a popped-up window.
thanks!
When the DocumentManager works in MDI Mode you can just work with mdi parent and child forms. So, I believe, you code for adding a new mdi-child into mdi-parent form can looks like this:
static void AddMdiChildFromMdiParent(Form mdiParent) {
Form child = new Form();
child.MdiParent = mdiParent;
child.Show();
}
Within the mdi-parent form you can call this code like this:
AddMdiChildFromMdiParent(this);
To add a new mdi-child from an existing mdi-child you can reuse the code above as follows:
static void AddMdiChildFromMdiChild(Form child) {
AddMdiChildFromMdiParent(child.MdiParent);
}
How can I maximize Iframe pop-up window in Webdriver ? As shown in the scrrenshot, there are many questions in "Add Work Experience", section which is opened in an iframe. Now when I am trying to answer those questions, I am getting, following exception:-
"Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: Error Message => 'Element is not currently visible and may not be manipulated'"
I believe this must be because the popup window opened in iFrame is not in maxmized state, and many questions are not visble, because same code works in ChromeDriver, and by default "Add Work Section" gets opened in maximized state in Chrome.
I have tried.
driver.switchTo().frame(iframes.get(0));
driver.manage().window().maximize();
But this is not working.
Following are detail repro steps :-
1) Go to talentconnect.pge.com/sap/bc/webdynpro/sap/hrrcf_a_unreg_job_search?sap-client=810&sap-wd-configId=ZPERJ_A_UNREG_JOB_SEARCH#
Username:- softwaretesting805#gmail.com
Password:- 1Selenium#
2) Search and Apply for any Job and go upto Work Info Page, when you click on Add Work tab, this popup come up, I am trying to Answer State question, which is currentl hidden in Scrrenshot, as All ids in these sites are dynamic, I am answering them using dom structure.
textElements = driver.getDriver().findElements(
By.xpath("//input[#type=\"text\"]"));
I got "question", and "Answer" in my input dto and I answer them in this way
if (question.contains("Employer")) {
textElements.get(0).sendKeys(answer);
continue;
} else if (question.contains("Start Date")) {
textElements.get(1).sendKeys(answer);
continue;
}
Run javascript that increase your iframe height and width, i have my own example:
((JavascriptExecutor) driver).executeScript("document.getElementById('containerId').style.height = '200px';");
or
((JavascriptExecutor) driver).executeScript("arguments[0].style.height = '200px';", element);
At times Maximize() fails to maximize the window, users can still maximize the window using a workaround mentioning the dimensions.
This code snippet is in Java...
Toolkit tool_kit = Toolkit.getDefaultToolkit ();
int width=(int) tool_kit.getScreenSize().getWidth();
int height=(int) tool_kit.getScreenSize().getHeight();
Dimension screen_Dimension = new Dimension(width, height);
web_Driver.manage().window().setSize(screen_Dimension);
Hope this helps
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();
I am using a Tree control with an XMLListContainer dataProvider.... I use an itemOpen event with the following code to update another data provider when a tree folder is opened (using small triangle) - the data provider contains all the <slide /> elements in that particular tree folder...
private function itemOpenEvent(event:TreeEvent):void {
slideDP = new XMLListCollection(event.item.elements("slide"));
slideDP.refresh();
}
If a second folder is opened thumbDP updates fine but when the first folder (or another closed folder) is clicked I want the same behaviour to happen (currently you have to close and reopen the first folder)
So I use a itemClick event - but this fires a ListEvent and I can't work out how to get the child elements from the XMLListContainer as easy... The code below throws an out of bounds exception
private function itemClickEvent(event:ListEvent):void {
treeFeed.getItemAt(event.rowIndex);
}
Can anyone help? Thanks :)
I would change your event listener to listen for a change Event, and use the selectedItem property of the Tree:
private function changeHandler(event:ListEvent):void
{
slideDP = new XMLListCollection(tree.selectedItem.elements("slide"));
slideDP.refresh();
}
You may need to cast selectedItem as XML or XMLList.