Unable to type in Text box field using sendKeys method. The xpath is working fine, since when i tried to click on textbox it works - selenium

driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
WebElement External = driver.findElement(By.xpath("//input [#id ='External_Reviewer']"));
External.click();
External.sendKeys("kevin");
The textbox is an autosuggestion with a people picker field. Is there any other way than using only "sendKeys" method.
Thanks in Advance.

You can use a JavaScript executor
External =driver.findElement(By.xpath("//input [#id ='External_Reviewer']"));
driver.executeScript("arguments[0].setAttribute('value', '"yourvalue"')", External);

Selenium executes so fast. You just need to add some wait after click is performed and then use sendKeys().
So, it will be like:
External.click();
Thread.sleep(2000);
External.sendKeys("kevin");

if sendKeys() not working, you can try with Actionsclass. Please try with below function:
public void typeTextIntoSpecialInput(WebElement elem, String input) {
Actions actions = new Actions(driver);
this.moveToElement(elem, true);
actions.sendKeys(input);
actions.build().perform();
}
I hope it will help.

I had faced similar issue, and clicking on the text box before sending keys worked for me

Related

Find element in selenium using xpath

I'm trying to find and click the element "Test 123" using Selenium Webdriver in C#. I've tried all the methods I can think of, but no good. I think the values are hidden before they are selected, but not sure. Any ideas, please?
enter image description here
Simple Xpath locator can do the trick:
public void ClickElementByXpath(string text) {
IWebElement element = Driver.FindElement(By.XPath("//li[contains(text(), '${text}')]");
element.Click();
}
ClickElementByXpath("Test 123");

Selenium SendKeys in CKeditor5 does not work for me

I located the ckeditor5 with findElement(By.cssSelector("p")).
I was able to click inside the editor but the function editor.sendKeys("Test") leads to the error message:
Cannot focus element.
Does someone have an Idea how I could put some Text inside the ck5 using Selenium?
I found it out, this worked for me: getDriver().switchTo().activeElement().sendKeys(keys);
Use the actions to click and sendkeys
Sample example below
IWebElement element = driver.FindElement(By.XPath("//p"));
Actions actions = new Actions(driver);
actions.MoveToElement(element);
actions.Click();
actions.SendKeys("New");
actions.Perform();

Not able to click button(WebElement) in Selenium Webdriver 3.7

I was trying to automate add to cart functionality in the following website, but 'Add To Cart' button is not getting clicked, though element is identified and code has been written to click on the button using Actions class and Javascriptexecutor.
Site: https://redmart.com/sales
Button: Add To Cart
Selenium Code:
WebElement element4 =
driver.findElement(By.xpath("//article[#id='contentSection'] //div[#class='productShelf']//ul/li[1]"));
WebElement element5 = element4.findElement(By.xpath("div[3]/div/a/span"));
actions = new Actions(driver);
actions.moveToElement(element4).moveToElement(element5);
Thread.sleep(3000);
actions.click();
actions.build().perform();
Can someone please suggest a solution which will click on Add To Cart button and added element should be displayed in cart as well?
Your xpath is not correct because it doesn't select the button.
Try this xpath "//li[#data-id='88800134']/div[3]/div/a" and let me know if this solve the problem.
driver.findElement(By.xpath("//li[#data-id='88800134']/div[3]/div/a")).click();
Later Edit:
WebDriver driver = new ChromeDriver();
driver.get("https://redmart.com/sales ");
driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);
WebElement element =driver.findElement(By.xpath("//li[#data-id='88800134']/div[3]/div/a"));
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", element);
I really think you are selecting the wrong element:
browser.find_element_by_xpath(".//*[#id='contentSection']/div/article/div[2]/div/div/ul/li[1]/div[3]/div/a").click()
browser.find_element_by_xpath(".//*[#id='contentSection']/div/article/div[2]/div/div/ul/li[2]/div[3]/div/a").click()
browser.find_element_by_xpath(".//*[#id='contentSection']/div/article/div[2]/div/div/ul/li[3]/div[3]/div/a").click()
browser.find_element_by_xpath(".//*[#id='contentSection']/div/article/div[2]/div/div/ul/li[4]/div[3]/div/a").click()
Anyway have a look on my answer in this post to ensure that you are getting the correct information ;)
python selenium click on button
Please try this xpath:
//ul[contains(#class,'productList')][1]//li[1]//a[contains(#class,'Button')]
It is for first ,,Add to Cart'' button on list.
If you want to click other product, just change index of product list or li tags in xpath.
Please also try clicking without using Actions.
driver.findElement(By.xpath("//ul[contains(#class,'productList')][1]//li[1]//a[contains(#class,'Button')]").click();
It can be an Actions issue.
I hope it helps!
Try with the below xpaths :
//ul[contains(#class,'productList')][1]//li[1]//a[contains(#class,'Button')]/span
This one is for the first item.
(//span[text()='Add to cart'])[1]
Try changing replacing your WebElement element5 to the code below:
WebElement element5 = element4.findElement(By.xpath("/div[3]/div/a/span/parent::node()"));
because it seems like you are trying to click a span element, that's why it's not doing anything

Selenium Web Driver

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.ElementEx‌​ists 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.

How can I send keyboard shortcut Alt + Shift + Z (hotkey) with Selenium 2?

I am trying send a shortcut with Actions.sendKeys, but it isn't working.
(New Actions(driver)).SendKeys(Keys.ALT, Keys.SHIFT, "z");
You can check this question to refer about this - Pressing Ctrl+A in Selenium WebDriver
Check the answer which uses the chord method. In your case, you can do this -
String selectAll = Keys.chord(Keys.ALT, Keys.SHIFT,"z");
driver.findElement(By.tagName("html")).sendKeys(selectAll);
This can also be done using Actions keyUp and keyDown functions.
WebDriver driver = new FirefoxDriver();
Actions keyAction = new Actions(driver);
keyAction.keyDown(Keys.ALT).keyDown(Keys.SHIFT).sendKeys("z").keyUp(Keys.ALT).keyUp(Keys.SHIFT).perform();
Try it:
SendKeys.SendWait("%+z")
Assuming you're using JavaScript,
Keys.chord(keys)
Also, the documentation is at https://www.selenium.dev/documentation/en/
Apart from the Keys.chord(Keys.ALT, Keys.SHIFT,"z"); method as suggested in the other/accepted answer, I would suggest you try the Robot framework for using keyboard shortcuts.
You can do something like;
Robot robot = new Robot();
Thread.sleep(1000);
robot.delay(3000);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_Y);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_Y);
I guess this would help sort your problem.