I need to click on a div icon. This is the html:
<div id="commandBarIconExcel"
tabindex="0" aria-label="Exp" role="btn"
class="commandBarItems__container"></div>
What i have tried:
driver.FindElement(By.CssSelector("div#commandBarIconExcel")).Click();
driver.FindElement(By.xpath("/html/body/div[1]/div/div/div/div[2]/main/div/div[2]")).Click();
driver.FindElement(By.Id("commandBarIconExcel")).Click();
new WebDriverWait(driver, TimeSpan.FromSeconds(100)).Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible((By.CssSelector("div#commandBarIconExcel"))));
new Actions(driver).Click(driver.FindElement(By.XPath("//div[#id='commandBarIconExcel']"))).Perform();
They all give unable to locate the error. Any suggestions, please?
This div opens after we select from some drop downs above it.
I was able to do it using JavaScriptExecutor
IWebElement elementa = driver.FindElement(By.CssSelector("div#commandBarIconExcel"));
IJavaScriptExecutor executor1 = (IJavaScriptExecutor)driver;
executor1.ExecuteScript("arguments[0].click()", elementa);
Related
How can i get element from below dropdwon, i have used Select command to select dropdowns, but here type is input.
<input class="tp-select-input" autocapitalize="none" autocorrect="off" autocomplete="off" spellcheck="false" data-testid="register-country" value="">
As dropdown you want to select value from is not a select type tag, Selenium Select method wont work on it. You have to follow below steps:
Click on Dropdown / or Arrow
Locate webelement you want to select from dropdown
Use java script executioner to click the option you want to select
Since you have not given complete HTML, below is the dummy code:
driver.FindElement(By.XPath("//input[#data-testid='register-country']")).Click() // Click on dropdown
IJavaScriptExecutor executor = (IJavaScriptExecutor)driver;
executor.ExecuteScript("arguments[0].click();", driver.FindElement(By.XPath("//*[text()='Austria']"))); //You can give more accurate xpath for country you want to select based on other HTML attributes
You can also try with below code
IWebElement element = driver.FindElement(By.ClassName("tp-select-input")); driver.FindElement(By.XPath("//span[text()='Australia']")); element.SendKeys(OpenQA.Selenium.Keys.Down); element.SendKeys(OpenQA.Selenium.Keys.Return);
I am using Selenium Webdriver using C#, but selenium isn't identifying my Modal Window.
I have tried:
IAlert alert = driver.SwitchTo().Alert();
alert.Accept();
But it doesn't work. In the code the modal has 'ID' but, it doesn't work either.
I need identify the modal and click in the button.
As per the HTML you have shared to click on the button with text as Close you need to induce WebDriverWait for the desired element to be clickable and you can use either of the following solutions:
Using CssSelector:
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("button.close[data-dismiss='modal'][aria-label='Close']"))).Click();
Using XPath:
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//button[#class='close' and #data-dismiss='modal'][#aria-label='Close']"))).Click();
I want to send instagram shipment with mobile imitation. but I need to click on a button for the new shipment. I tried everything about button click but I did not manage it.
public static void HoverMouseOverClicks(IWebElement element)
{
Actions action = new Actions(insta);
action.MoveToElement(element);
IJavaScriptExecutor executor = (IJavaScriptExecutor)insta;
executor.ExecuteScript("arguments[0].scrollIntoView(true);arguments[0].click();", element);
}
code click-through code you've seen above
HoverMouseOverClicks(insta.FindElement(By.XPath("//*[#id='react-root']/section/nav[2]/div/div/div[2]/div/div/div[3]/span")));
I try this and I still can not get the result.
insta.FindElement(By.XPath("//*[#id='react-root']/section/nav[2]/div/div/div[2]/div/div/div[3]/span")).Click();
This code sometimes clicks and sometimes does not click.
The XPath path never changes.
Relevant HTML:
<div class="q02Nz _0TPg" role="menuitem"><span class="glyphsSpriteNew_post__outline__24__grey_9 Szr5J">Yeni Gönderi</span> <span class="glyphsSpriteNew_post__outline__24__grey_9 Szr5J">Yeni Gönderi</span></div>
what should I do?
As per the HTML you have shared to click on the element with text as Yeni Gönderi you need to induce WebDriverWait for the element to be clickable and you can use the following solution:
new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//div[#role='menuitem']//span[contains(#class, 'glyphsSpriteNew_post__') and contains(.,'Yeni Gönderi')]"))).Click();
I'm trying to locate an element using XPath but my code is incorrect and I'm not sure of the write syntax.
I entered the code below which isn't working.
IWebElement customizeButton = driver.FindElement(By.XPath("//*[#id='container']/div/div[1]/div[1]/div[2]/button[2]"));
The HTML code for the element is below
<button class="button u-space-ls js-customize-button button--primary " data-tooltip="{"placement":"left","title":"Customize"}" data-reactid=".0.0.0.3.3"><span class="icon icon-gear" data-reactid=".0.0.0.3.3.0"></span><span class="u-small-hidden u-medium-hidden" data-reactid=".0.0.0.3.3.1"> Customize</span></button>
Can you please let me know how I should correct my code?
Thanks
If you are looking to locate the button with text as Customize as the element is JavaScript enabled element you have to induce WebDriverWait as follows :
wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
IWebElement customizeButton = wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//button[#class='button u-space-ls js-customize-button button--primary']//span[#class='u-small-hidden u-medium-hidden']")));
I'm new to XPath and CssSelector.
below is the target html source.
<input value="1" name="uji.model.611876.button" type="radio"></input>
611876 is a random number.
I tried with the code:
driver.FindElement(By.Id("//input[#value=\"1\"]")).Click();
and
driver.FindElement(By.Id("//input[#value='1']")).Click();
but the Unable to locate element error occurred.
I need help for that situation. Thank you for reading.
If you get ElementNotVisibleException try to wait some time until target input become visible:
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(15));
IWebElement element = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//input[starts-with(#name, \"uji.model.\")][#type=\"radio\"]")));
element.Click();
You can do something like
driver.findElement(By.tagName("input")).Click();
You can try JavascriptExecuter to execute javascript code if it is causing problem -
IWebElement element= driver.FindElement(By.XPath("//input[#value=\"1\"]")));
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
js.ExecuteScript("arguments[0].click();", element);