I am new to Selenium and I have the following situation.
My html:
<div class="activeThumbnail thumbnail simple animated zoomIn" data-url="/report/sales-vs-price" style="height: 332px;">
<div class="caption">
<p class="thumbReportTitle">
Sales vs Price
</p>
</div>
</div>
I need to simulate a click in the link so it opens the report page. I tried a couple of different options based on different responses (trying to access the link or the text):
1. This throws an exception of "element not visible"
driver.FindElementByCssSelector("a[href*='sales-vs-price']").Click();
2. Here I tried to fix the "not visible" exception so now it doesn't throw an error but it also doesn't do anything:
Actions builder = new Actions(driver);
Actions click = builder.MoveToElement(driver.FindElementByCssSelector("a[href*='sales-vs-price']")).Click();
click.Build().Perform();
or
Actions builder = new Actions(driver);
Actions click = builder.MoveToElement(driver.FindElementByXPath("//*[contains(text(),'Sales vs Price')]")).Click();
click.Build().Perform();
3. This throws an expception of "Unable to locate element"
driver.FindElementByPartialLinkText("a[href='sales-vs-price']").Click();
4. Or this, with the exception: "element not visible":
driver.FindElementByXPath("//*[contains(text(),'Sales vs Price')]").Click();
I am not sure what I am doing wrong... Does any one know if I can access data-url? Or does someone have any other ideas?
Thanks!
Can u try this.
driver.FindElement(By.PartialLinkText("Sales vs Price")).click();
if element not found exception is thrown on using above command. use implicit wait(to ensure page is loaded fully).
if no action is performed on above command.use
driver.FindElement(By.PartialLinkText("Sales vs Price")).sendKeys(Keys.Control);
driver.FindElement(By.PartialLinkText("Sales vs Price")).click();
Keys.Control will bring focus to desired element. I faced similar issues with IE driver.
Related
enter image description here
enter image description here
enter image description here
enter image description here
When I start the program, it starts and runs fine until it goes to the point where I want the driver to click the button and it throws me the exception the web element not intractable. I've tried a lot of methods but none of them worked. The problem I think is that when this button is clicked the HTMl changes. Please help :D
this is the line of code that trows me the exception (C#) :
driver.FindElement(By.XPath("//button[#id='exifInfoMobile']")).Click();
error : OpenQA.Selenium.ElementNotInteractableException: 'element not interactable
(Session info: chrome=103.0.5060.114)'
and this is the HTML :
<li class="photo-info">
<button class="btn btn-photo-info" id="exifInfoMobile">
<span class="text">info</span>
</button>
</li>
I've tried with WebDriverWait , By class name and by id but it didn't work. I think it has something to do with a model because when this button is clicked, the sites html changes by adding an info panel on the right. Sorry again for the bad question but its my first time asking one here.
If a regular .click() does not work, you can click with JavaScript.
You can use this
var element = sel.driver.FindElement(By.Id("exifInfoMobile"));
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click();", element);
or this
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
var element = sel.driver.FindElement(By.Id("exifInfoMobile"));
js.ExecuteScript("arguments[0].click();", element);
I have a test to click the cookie policy close icon on our web page in Mobile Emulation mode but when my test tries to click on the close icon I get the error
"An exception of type 'OpenQA.Selenium.WebDriverTimeoutException' occurred in WebDriver.dll but was not handled in user code"
It seems to cannot find the element. I have also tried waiting for the page to load, element to be displayed and a hard coded wait of 5 seconds. Still no luck.
My XPath which I have tried is:
[FindsBy(How = How.XPath, Using = "//div[contains(#class, 'messageBoxContainer')]//div[contains(#class, 'messageBoxCloseButton icon-cross')]")]
Another Xpath I have also tried:
//div[#class='messageBoxCloseButton icon - cross']"
The HTML snippet is:
<div class="messageBoxContainer">
<div class="messageBoxTextInner">
<div class="messageBoxTitle">Cookies on Company a</div>
<div class="messageBoxBody">
<span class="cookiePolicyText">Company a uses cookies to give you the best experience possible. Please read our</span>
<span class="cookiePolicyLinkText" data-tap-recogniser="true">Cookie Policy</span> for more details.</div></div>
<div class="messageBoxCloseButtonContainer">
<div class="messageBoxCloseButton icon-cross" data-tap-recogniser="true"></div></div></div>
My Selenium C# snippet is:
public void ClickCookieCloseIcon()
{
Actions.Click.Element(Browser, CookieCloseIcon);
}
How do I click the x close icon from this cookie policy please. Is it my locator causing the problem?
The locators should be the same as Desktop or can Mobile Emulation some locators behave differently?
Thanks for your help.
Riaz
I have it working now. Our contractor used this Xpath and it is now working
[FindsBy(How = How.CssSelector, Using = "div[class='cookieWidget'] div[class='messageBoxCloseButton icon-cross']")]
I'm trying to run some automated tests in Sitecore 8.1 using Chrome and Selenium and c#. My code doesn't want to find any elements within the Sitecore pages, specifically the experience editor.
I am encountering the "unable to locate element" warning.
For eg: an item I want to .Click() is the toolbar ribbon button to expose the toolbar menu.
Here's the element:
<a data-sc-id="QuickRibbon" data-sc-click="trigger:button:toggleshow" data-sc-command="" data-sc-сontrolstaterequest="" data-sc-controlstateresult="" data-sc-postponedcall="" data-sc-ispressed="false" class="sc-quickbar-item sc-quickbar-button sc_QuickbarButton_53 data-sc-registered" title="Toggle the ribbon." data-sc-pagecodescriptfilename="" data-bind="ispressed: isPressed, visible: isVisible, click: click, command: command, enabled: isEnabled" data-sc-require="/-/speak/v1/ribbon/QuickbarButton.js" href="#" style="float:right"><img src="/sitecore/shell/client/Speak/Assets/img/Speak/Common/16x16/white/navigate_down.png" alt="Toggle the ribbon."></a>
Here's its XPath:
/html/body/div/div/div[1]/nav[1]/a[3]
I have extended the wait time to allow it to become visible as it can take a few seconds to load these pages. But this didn't work.
I have tried:
driver.FindElement(By.XPath("/html/body/div/div/div[1]/nav[1]/a[3]/img")).Click();
which gave me the "unable to locate" error
driver.findElement(By.className("class="sc-quickbar-item sc-quickbar-button sc_QuickbarButton_53 data-sc-registered"")).Click();
which gave me an error about unable to use compounded classnames.
I've tried a whole host of other options/combinations trying to pick up the alt text etc but I just can't get it to pick up the element.
Any ideas? Let me know if you need any more info.
Thanks
Change this line
driver.findElement(By.className("class="sc-quickbar-item sc-quickbar-button sc_QuickbarButton_53 data-sc-registered"")).Click();
to below line :-
driver.findElement(By.className("sc-quickbar-item sc-quickbar-button sc_QuickbarButton_53 data-sc-registered")).Click();
Edited 1..
If compound class does not work here you can perform action by using xpath as below :-
var wait = new WebDriverWait(driver, TimeSpan.FromMinutes(1));
var clickableElement = wait.Until(ExpectedConditions.ElementToBeClickable(By.xpath("//a[#data-sc-id='QuickRibbon']")));
clickableElement.Click();
Edited 2..
You need to switch frame before perform action if your element is present inside a frame as below :-
driver.SwitchTo().Frame("your frame name or id");
Hope it will work...:)
following suggestions from #Software_engineer I have managed to write this which works:
Thread.Sleep(6000);
driver.SwitchTo().Frame(driver.FindElement(By.Id("scWebEditRibbon")));
var wait = new WebDriverWait(driver, TimeSpan.FromMinutes(1));
var clickableElement = wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//a[#data-sc- id='QuickRibbon']")));
clickableElement.Click(); //click to drop down the toolbar
driver.SwitchTo().DefaultContent();
I needed to switch to the iframe!
I am using Selenium in C# to Enter data into textboxes on a webpage:
But i am getting this error:
OpenQA.Selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
I'm using #name, but there are 2 controls on the page with name="MinPrice"
heres the HTML:
<div class="form-group for-sale">
<label>Min Price</label>
<input class="form-control" name="MinPrice" min="0" placeholder="Minimum Price" value="" type="number"></input>
and this is the xpath I'm using:
txtMinPrice = Driver.Instance.FindElement(By.Name("MinPrice"));
I also tried using XPath, but similar results:
txtMinPrice = Driver.Instance.FindElement(By.XPath("//input[contains(#name,'MinPrice') and type='number']"));
If anyone has any type of idea....this is driving me nuts.
ElementNotVisibleException exception occurs when selenium can find an element in the DOM but it is not rendered on the screen.
When I have encountered this error before it has been generally caused by one of three things:
Selenium is trying to interact with an object that is present in the DOM but has not yet rendered on the screen, in which case you might consider adding some type of delay. (Avoid sleep if you can but it is useful for debugging)
The element is below the visible screen, in which case you would need to scroll to interact with it.
There is an overlapping element that is blocking the display of the element.
Add a sleep(10) in to make sure everything on the page has loaded first before any user actions are preformed. If that doesn't work also add
driver.manage().window().maximize() at the start of your test to make sure all the page elements is in view.
If that doesn't work its your xpath. Try something like //*[#class="form-group for-sale"]/input
Or use the Firefinder add on in mozilla firefox to check your xpath is valid and exists on the page.
Selenium is good at scrolling down to view an item, but when it comes to Scrolling back up it's a PiA, and usually throws that exception. I usually just do something like
element.SendKeys(Keys.Home);
Thread.Sleep(100);
I m doing the website automation thru Selenium webdriver in Firefox. Everything is fine but I dont know how to click the radio button.
There are two radio buttons in the web (i) Family Information and (ii) Individual Information. Target information obtained in the Selenium IDE.
(i) name=indFamily
(ii) document.pebPostLogin.indFamily[1]
I can easily click the first one Family information thru following code:
driver.FindElement(By.Name("indFamily")).Click();
But dont know the C# command for the second one "Individual Information". I have recorded the actions in Selenium IDE in Firefox and exported into C# file but DOM commands are not exported in C#. Following error message seen in C# file.
// ERROR: Caught exception [Error: Dom locators are not implemented yet!]
Please find below the source code identified thru Firebug.
<input name="indFamily" tabIndex="6" onkeypress="submitOnEnter(window.event.keyCode, document.pebPostLogin)" type="radio" value="Family"/>
<input name="indFamily" tabIndex="7" onkeypress="submitOnEnter(window.event.keyCode, document.pebPostLogin)" type="radio" value="Individual"/>
Please help me out...
It has been fixed using Xpath. The code is below:
driver.FindElement(By.XPath("//input[#value='Individual']")).Click();
Thanks to Alexander and http://www.w3schools.com/xpath/xpath_syntax.asp
Try following code:
driver.FindElement(By.XPath("//input[#name='xxxx' and #value='xx']")).Click();
xxxx = element name
xx = value (for eg., yes)