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.
Related
I'm clicking in on a button on a webpage using Selenium. The button creates a file which can be downloaded now. For this, a overlay is shown in Internet Explorer (yes, I HAVE to use this browser, it's a requirement).
Now I have to check the text on the overlay ("öffnen oder speichern" see my screenshot). I can imagine that it there is a solution using JavaScriptExecutor but I simply couldn't found a solution.
I also tried to find it in innerHTML-without success.
It's not an alert so I can't use Driver.switchTo().alert();
My Code still doesn't contain more than clicking on a button using XPath.
Actions action = new Actions(driver);
JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
String exportButtonXPath = generalHelper.getProperty("buttonCSVExportXPath");
WebElement exportButton = driver.findElement(By.xpath(exportButtonXPath));
action.click(exportButton).perform();
Do you have a solution how can test the text on this popup?
Actually, it is not related to the web browser any more. You need to interact with it as a desktop window.
->If you want to click it using selenium, you can locate its coordinates and use click by coordinates using selenium.
->If you want to accept to download it, you can find a capability to accept downloading by default (except IE).
->If you want to check the text value, for sure you've to automate it as desktop not as a web.
After testing logging in https://www.pcbway.com/ I want to test logout.
In order to do this I need to hover on a div so that the sign out button appears. I tried using
Actions actions = new Actions(driver);
actions.moveToElement(element).build().perform();
but it did not work. I tried using the javascript exector
JavascriptExecutor executor = (JavascriptExecutor)driver; executor.executeScript("arguments[0].click();", element);
but it also did not work. I can see that the hover works by using mouseout jquery (screenshot below)
I am using chrome 58 with selenium 3.4.0.
You can try to force it open by adding the class the element receives when the menu is open.
executor.executeScript("$('.nav-user-account').addClass('user-account-unfold')")
Then you can click the element in the menu.
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.
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();
I'm facing an issue writing a Selenium program using Java.
I'm trying to click the following link :
חפש
by using the following code:
WebDriver driver = new HtmlUnitDriver();
driver.get("http://mapi.gov.il/Pages/LotAddressLocator.aspx");
((HtmlUnitDriver) driver).setJavascriptEnabled(true);
WebElement element = driver.findElement(By.id("AddressInput"));
element.sendKeys("הנגיד 16");
WebElement button = driver.findElement(By.id("helkaSubmit"));
button.click();
String pageSource=driver.getPageSource();
System.out.println(pageSource);
But it doesn't seems like the button was clicked at all, since the page content which must change after clicking the link, does not change at all.
I need to find a way to check whether the link was clicked at all, or to find why it was not clicked.
Can anyone point me to the solution ?
EDIT:
Using executor.executeScript("document.getElementById('helkaSubmit').href='http://www.google.co.il';");
executor.executeScript("document.getElementById('helkaSubmit').click();");
Worked just fine, so javascript is enabled and clicking is executed, but for some reason the original code does nothing.
try this,
driver.findElement(By.id("helkaSubmit")).click();