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);
Related
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 have this button on which a text is written. The text on the button is coming from a database and changes regularly. I want to save this text in a variable for further processing. The html tag is given below
<button type="button" id="hvac1_sequence" class="btn btn-warning" style="width:60px;">Lag</button>
I want to save "Lag" in the variable through Selenium Webdriver using C#. I have tried these following codes but none of them worked as I experienced error.
var element = driver.FindElement(By.Id("hvac1_sequence")).Text
var element = driver.FindElement(By.ClassName("btn btn-warning")).Text
var element = driver.FindElement(By.XPath("//button[#id='hvac1_sequence']")).Text
I have also tried to save them in IWebElement rather than var. Still same error. Can anyone help me?
Edit 1 : Error is Something like Selenium cannot find the Id or Selenium cannot find the Xpath given
Edit 2 : Exact Error
An unhandled exception of type 'OpenQA.Selenium.NoSuchElementException' occurred in WebDriver.dll. Additional information: no such element: Unable to locate element: {"method":"id","selector":"hvac1_sequence"}
The error was occuring because the frame was not selected. I used the following method to select the frame
driver.SwitchTo().Frame("temporary");
Where the temporary is the id of iframe
The link that I am trying to click is not being recognized at all. Developer tools in chrome shows me the link as in structure below:
<main
<div
<ifreame
#document
<html
<body
<form
<div
::before
<a href=wizard_view.do? sys_action=sysverb_wizard_ans&WIZARD:action=follow&wiz_referring_url=&wiz_collection_key=&wiz_collectionID=&wiz_collection=&wiz_collection_related_field=&wiz_view=&wiz_action=sysverb_new&sys_id=ea7d96126f92a100f3ae60526e3ee4e0&sysparm_query=active=true&sysparm_target=&sys_target=change_ddfdff>Standard (from Template)
</a>
::after
</div>
....
How do I identify and click this particular text link?I tried css selector,xpath etc but didn't work
anchors = dd.findElements(By.linkText(Standard (from Template)));
anchors2 = dd.findElements(By.cssSelector(a[href*='ea7d96126f92a100f3ae60526e3ee4e0'] )));
Also there are a 10 div sections with same class name each of which is a text link. I want to click on of them (see above)
When you try to search for elements inside an iframe, you have to switch to that frame first
driver.SwitchTo().Frame(driver.FindElement(By.Id("_the_frame_id")))
Switching to frame solved my issue . But in the next page also I have the same freme (id/name) and I am not able to identify an input text box even though I have already switched to the frame.
I am getting 'NoSuchElementException' when:
driver.switchTo().frame(driver.findElement(By.id("gsft_main")));
WebElement stdFromTemplate = driver.findElement(By.linkText("Standard (from Template)"));
stdFromTemplate.click();
WebElement stTemplate = driver.findElement(By.id("cced8819db987e08dee9f7b31d961989_text"));
This last line(which is a new page now after clicking on the link that i was mentioning in the initial question) line give me 'NoSuchElementFoundException'
I am trying to locate a button in a form... but it doesnt find it...
I have tryed using threading.sleep(5000); but it dont help.
I have tryed so many ways but nothing helped me it always says that it cant locate the button...
here is my code:
IWebElement startb2 = driver.FindElement(By.XPath("//form/*[#name='start']"));
here is the html code of the form:
<form method="post" action="php/PickFruits.php">
<input type="submit" name="start" value="התחל לקטוף" class="button_submit" style="margin-right:-97px;">
</form>
I don't want to use the value because it is in Hebrew... and I cant use it in the c# console... please help me guys.
Edit:
Now its find the location of the input but it doesnt click on it... code:
IWebElement startb = driver.FindElement(By.XPath("//*[#type='submit']"));
startb.Click();
To switch to an iframe, use the below code.
//To find the iframe
IWebElement Object = driver.FindElement(By.XPath("//*[#class='active_iframe']");
//To switch to and set focus to the iframe
driver.SwitchTo().Frame(Object);
And then perform click operation.
IWebElement startb = driver.FindElement(By.XPath("//*[#type='submit']"));
startb.Click();
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.