How to Handle Pop Up IFrame Window In Selenium - java

I am new in Slenium.
I am trying to handle the pop-up Form.
When I click in New Button the pop-up form like this will open.
I try the handle this by alert(), pop up handling and also by Child Browser Handling. But didn't get the solution.
Please suggest some solution for this issue

If it's an <iframe> element then you need to switch WebDriver to this frame in order to work with it. Here's an example of how you can do this:
By locIframe = By.xpath("//iframe[#name='popup']");
driver.switchTo().frame(driver.findElement(locIframe));
// driver is an instance of RemoteWebDriver
The Xpath locator is just an example: you need to write your own here. Also you can use any other locator to find that <iframe> element in the page source.
After switching to iframe element WebDriver will see it's page source and will be able to work with it.

I also faced the similar issue. When clicked on EDIT Button in the parent window, an iFrame pop-up appears as shown below:`
As mentioned that you tried to handle using alert() or pop up handling and also by Child Browser Handling. But none of them will work since it is an iFrame pop-up. So you need to switch WebDriver to this frame in order to work with it.
For my case I did using the following code:
driver.switchTo().frame(3);
To find the index of the frame you can use Selenium IDE.

Related

Unable to locate the element when Page factory is used for webelements

Here i am unable to click the iframe href using the Page factory but if i try seperately without pagefactory i am unable to click the Href
DOMImage: enter image description here
#FindBy(xpath="//*[#id="content"]/div/ul/li[2]/a")
WebElement iFramelabeltext;
Tried various approachs:
//a[normalize-space()='iFrame']
//a[#href='/iframe']
Need help in solving this ?
Firstly, you need to understand what is a Frame actually - it's a html code block inside entire html page code. So Selenium cannot directly access it.
You need to switch to that Frame and then perform needed actions.
How to deal with frames, see here - https://www.guru99.com/handling-iframes-selenium.html

I want to perform click action on button present under "svg" layout using selenium library

I want to perform click action on a button present under .svg layout using Selenium (Java bindings).
For example, I want to click on the button element, but every time I try to find an element by xpath, I get exception `enable to locate element
I read that with Selenium its tricky to click on element present under the .svg.
Is there anybody who knows a solution because, I haven't found a suitable solution on the net by myself.
Find below HTML code look likes this way:
My code:
List <WebElement> frame1=driver.findElements(By.xpath("//iframe[contains(#id,'-06636000002Pb2L')]"));
System.out.println(frame1.size());
System.out.println(frame1.get(0).getAttribute("title"));
driver.switchTo().frame(0);
ElementaryOperations.Sleep(3000);
System.out.println("New relation frame found");
driver.findElement(By.cssSelector("#newrel")).click();
After switching to frame successfully, I am not able to click on the element present under the SVG layout. Please refer to the attached screen shot(link)
this is how you should be able to identify SVG node and then sub nodes of that.
//*[local-name() = 'svg']
use this code
driver.findElement(By.id("rfb")).click();
try using class attribute of the button using CSS Selectors:
driver.findElement(By.cssSelector(".btn.btn-primary")).click()

Issue with focus in ie browser using selenium webdriver code

Firstly i need to mouse over and then it opens a drop down then i will click on that link.Its working fine in firefox,chrome and issue is in ie.
Here is the code
WebElement element=driver.findElement(By.xpath("/html/body/div/span/form[2]/div[1]/div[1]/div[3]/div[2]/ul/span[3]/li/a"));
Actions act=new Actions(driver);
act.moveToElement(element).build().perform();
WebElement element2=driver.findElement(By.xpath("/html/body/div/span/form[2]/div[1]/div[1]/div[3]/div[2]/ul/span[3]/li/ul/span[1]/li/a"));
Actions act1=new Actions(driver);
//act1.click(element2);
act1.moveToElement(element2).click(element2).build().perform();
It works even in IE browser, when we use this piece of code
caps.setCapability("requireWindowFocus", true);
If we use requiredwindow focus its working fine even in IE browser so no issues with locators
But am not encouraged to use above requiredwindowfoucs code in my project.
Is there any other way to do it.
The issue in Ie browser when we are not using requiredwindowfocus, it is clicking on some other link, so am assuming the problem is with focus.
so kindly help me with this issue without using requiredfoucswindow
I have has similar issues in my project. In IE, clicking drop down values does not work. I have a pretty weird and unexpected solution for this. Find the element before performing the operations. I am assuming that this is required because when you move to element1 and when trying to find element the IE Xpath processor messes up the focus.
WebElement element=driver.findElement(By.xpath("/html/body/div/span/form[2]/div[1]/div[1]/div[3]/div[2]/ul/span[3]/li/a"));
WebElement element2=driver.findElement(By.xpath("/html/body/div/span/form[2]/div[1]/div[1]/div[3]/div[2]/ul/span[3]/li/ul/span[1]/li/a"));
Actions act=new Actions(driver);
act.moveToElement(element).build().perform();
act.moveToElement(element2).click(element2).build().perform();
Please try this and let me know if this works for you too!!
Also, consider using relative XPaths instead of the absolute XPaths you have used. The second Action is not required. One action should do the trick.
EDIT Based on user comment
Move to element1 is working and the list is getting displayed. So I am assuming that element2 is visible and so we can directly click on it without using the Actions class
Actions act=new Actions(driver);
act.moveToElement(element).build().perform();
element2.click();

Webdriver throws Nosuchemelent exception for modal dialog(which is overlay )

I have modal dialog overlayed. and unable to click or find elements on the dialog popup.
I have this code below to find clipAllElement.
clipAllButton = getWait().until(
ExpectedConditions.visibilityOf(clipAllButton));
clipAllButton.click();
If I execute the below javascript it works fine.
/*String str = "jQuery('.mod-featuredtoday-flyout .ft .cta-button').trigger('click')";
((JavascriptExecutor)getDriver()).executeScript(str);*/
but selenium throws nosuchelement exception
I am using FF 21 and Selenium 2.33
did someone see similar issue and knows any workaround
If the modal is contained in an iframe you will need to switch to the iframe before selecting elements within.
driver.switchTo().frame("foo");
When you are done with the iframe, switch back to the main document:
driver.switchTo().defaultContent();

Workarounds for Selenium not clicking button with InternetExplorerDriver

I've got a button on a webpage that Webdriver will not click when I'm running via IE - I've tried the below workarounds but no luck -
Clicking via Javascript:
((JavascriptExecutor) driver).executeScript("$(arguments[0]).click()", webElement)
Using SendKeys:
webElement.SendKeys(keys.Enter)
Using the Action Builder
Actions test = new Actions(driver);
test.moveToElement(webElement);
test.clickAndHold();
test.release();
test.build();
test.perform();
Making sure the window is the active one, then clicking on the parent object, then the object itself
Problem is, none of them work. I've checked in Firefox and Chrome and the script runs fine. I've confirmed that the element is being found when using IE. Are there any other workarounds I can try?
Seems you are tyring to use JQuery style click... normal javascript style click should work.
Try this:
((JavascriptExecutor) driver).executeScript("arguments[0].click();", webElement)
I always found successful with the following for clicking an element in IE.
If is a checkbox/radio: webElement.click();
Clickable input element: webElement.sendKeys("\n");
For other elements, use the above said JS style click.
If the button is a form submit button, you can use : webElement.submit() on another field of the form.

Categories

Resources