Please see pic below. I have tried to select the input tag through the following method using Selenium:
1. `element.Click();`
2. `element.SendKeys(Keys.Enter);`
3. Actions action = new Actions(Browser.Driver).MoveToElement(element);
action.Click().Perform();
I am trying to click the checkbox by returning it through a property in code that has the following code:
WebDriverWait wait = new WebDriverWait(Browser.Driver, TimeSpan.FromSeconds(60));
IWebElement checkbox = wait.Until(ExpectedConditions.ElementExists((By.CssSelector("label[for='PerformerIndependence_AcceptTermsAndConditions']"))));
return checkbox;
or
WebDriverWait wait = new WebDriverWait(Browser.Driver, TimeSpan.FromSeconds(60));
IWebElement checkbox = wait.Until(ExpectedConditions.ElementExists((By.CssSelector("input#PerformerIndependence_AcceptTermsAndConditions"))));
return checkbox;
For some reason If I run the code in debug mode to test the element returned to click it will click. If I just run my test in run mode using Visual Studio2015, the checkbox is not clicked. The method using the element to click for the three attempts is wrapped in a try/catch block. Please help!!!
Screenshot
I am also facing this issue. Click on checkbox is not working in Edge..
There are two work around of this:
click using JS
use action class..
WebElement element=driver.findElement(By.id("abc"));
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", element);
==========================================================
Actions action = new Actions(driver);
action.moveToElement(element).click().perform();
Both worked fine in my case.
Related
I am currently looking for a solution to click on Sava button in chrome print preview window with selenium Java.
Is there any way we can handel chrome print preview page?
I have tried with the Robot class, but it seems not reliable/stable for my application.
Could you please someone help me to achieve this with selenium Java.
I fail to see any "Save" button on print preview page for Chrome browser
Here is how you can click "Cancel" button, I believe you will be able to amend the code to match your requirements:
First of all make sure to wait for the preview page to be available using Explicit Wait
Change the context to the print preview window via WebDriver.switchTo() function
All the elements at the print preview page are hidden in ShadowDom therefore you will need to:
Locate the element which is the first parent of the element you're looking for
Get its ShadowRoot property and cast the result to a WebElement
Use the WebElement.findElement() function to locate the next parent
repeat above steps until you reach the desired button
Example code just in case:
new WebDriverWait(driver, 10).until(ExpectedConditions.numberOfWindowsToBe(2));
driver.switchTo().window(driver.getWindowHandles().stream().skip(1).findFirst().get());
WebElement printPreviewApp = driver.findElement(By.tagName("print-preview-app"));
WebElement printPreviewAppConten = expandShadowRoot(printPreviewApp, driver);
WebElement printPreviewSidebar = printPreviewAppConten.findElement(By.tagName("print-preview-sidebar"));
WebElement printPreviewSidebarContent = expandShadowRoot(printPreviewSidebar, driver);
WebElement printPreviewHeader = printPreviewSidebarContent.findElement(By.tagName("print-preview-header"));
WebElement printPreviewHeaderContent = expandShadowRoot(printPreviewHeader, driver);
printPreviewHeaderContent.findElements(By.tagName("paper-button")).get(1).click();
where expandShadowRoot function looks like:
private WebElement expandShadowRoot(WebElement parent, WebDriver driver) {
return (WebElement) ((JavascriptExecutor) driver).executeScript("return arguments[0].shadowRoot", parent);
}
Save button will not work because page is not part of webpage. selenium only support web based application.
But you can use SIKULI to handle above scenario.
We are working on IE Automation using Selenium Web driver in C#.Net.
We are getting an exception in handling model popup window. We supposed to do below the action.
When we click on Link button it will open a popup window then we need switch to popup window selecting check box options and click on Submit button.
When clicking on Link button we are able to open the popup window. But here we are facing an issue like the child popup window is not loading with data and getting HTTP 500 Internal server Error.
I don't understand sometimes it was working properly with the same code but not all the times I am getting above issue when I am trying to perform above actions on child window.
is this any IE settings issue or my code issue even i ignored protected mode settings in IE settings.
I am trying with below code :
js.ExecuteScript("arguments[0].click();", driver.FindElement(By.XPath("//*[#id='ByNewNotes']")));
(or)
string jsWindowString = "NewWindow('pop_Type.jsp?Type=External&IuserId=NUVJK50'," + sessionId + ",'400','500');return false";
((IJavaScriptExecutor)driver).ExecuteScript(jsWindowString);
Could you please help on this issue.
Thanks in Advance.
Instead of using ExpectedConditions.ElementExists use ExpectedConditions.elementToBeClickable or presenceOfElementLocated
WebDriverWait wait = new WebDriverWait(driver, 60);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath(""//*[#id='ByNewNotes']")));
element.click();
Either Try to use FluentWait. Create a by function of your element which you want to wait and pass it in below method
WebElement waitsss(WebDriver driver, By elementIdentifier){
Wait<WebDriver> wait =
new FluentWait<WebDriver>(driver).withTimeout(60, TimeUnit.SECONDS) .pollingEvery(1, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
return wait.until(new Function<WebDriver, WebElement>()
{
public WebElement apply(WebDriver driver) {
return driver.findElement(elementIdentifier);
}});
}
Hope it will help you :)
Have you tried
Thread.Sleep(2000);
We had the same issues and solved it with this simple way.
Does anyone know how to click log out button? I tried using driver.findElement(By.linkText("Log out"));
But it returned an error saying element is not found. Is it because the list is dynamically generated?
You should try using WebDriverWait to wait until elementToBeClickable it works for me as below :-
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement accountSettings = wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Account Settings")));
accountSettings.click() //this will click on setting link to open menu
WebElement logOut = wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Log Out")));
logOut.click() // this will click on logout link
Hope it helps...:)
I assume, after click on arrow button, Log Out button appers in ur code. So to click on that log Out button, use the below portion as cssSelector:
a[data-gt*='menu_logout']>span>span._54nh
driver.findElement(By.cssSelector("a[data-gt*='menu_logout']>span>span._54nh"));
Hi I am trying to access a submenu in selenium using c#. On my the website that I am testing the mouseover to the menu opens another submenu1,mouseover to submenu1 options open submenu2. I want to click on one of the submenu2 options. I tried to run below, everytime it throws an error of element not visible on custonboarding.Click();
Actions builder = new Actions(driver);
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
var hoverover = driver.FindElement(By.XPath("menu1"));
builder.MoveToElement(hoverover).Build().Perform();
var hoverover1 = driver.FindElement(By.XPath("submenu1));
builder.MoveToElement(hoverover1).Build().Perform();
var custonboarding = driver.FindElement(By.XPath("submenu2"));
custonboarding.Click();
Can someone help me out here?
It might take some time for the element to fully load. You can use explicit wait and ExpectedConditions to wait for the element to be visible
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
IWebElement custonboarding = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("submenu2")));
custonboarding.Click();
This will wait up to 5 seconds for the element to be visible.
Help me please.
Selenium does not click on element and element is clickable(selenium does not generate exception).
I try use Id, css, xpath locators, nothing did not help me.
What should i do to decide my problem?
Java code example.
WebElement sector = webDriver.findElement(By.id("sector-1"));
sector.click();
After click system must open this page
Seems that you try to interact with object inside a <svg> element. If so, you cannot manage it's child elements simply using click() method.
Try this instead:
WebElement svgObject = driver.findElement(By.xpath("//polygon[#id='sector-1:canvas']"));
Actions builder = new Actions(driver);
builder.click(svgObject).build().perform();
Use below XPath :
WebElement sector = webDriver.findElement(By.xpath("//g[#id='sector-1']/polygon"));
sector.click();
OR
WebElement sector = webDriver.findElement(By.xpath("//polygon[#id='sector-1:canvas']"));
sector.click();
I decide my problem.
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[#id=\"sector-2:canvas\"]")));
WebElement svgObject = webDriver.findElement(By.xpath("//*[#id=\"sector-2:canvas\"]"));
Actions builder = new Actions(webDriver);
builder.click(svgObject).build().perform();