Selenium SendKeys in CKeditor5 does not work for me - selenium

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();

Related

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

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

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

How to click on a check box in a new window through selenium webdriver

I am trying to make this check box click but not I'm not able to click on check box.
Please send me the xpath or css
I tried:
xpath
//div//*[#id='thCheckBox']
.//*[#id='searchOrderModel']/div/div/div[3]/div/button[2]
There is a label next to the checkbox. You can try to click on the label then it will click the checkbox using below x-path.
//label[#for='thCheckbox']
As per the HTML you have provided and your question as the Check Box is on a new window to click() on the Check Box you have to induce WebDriverWait for the Check Box to be clickable and you can use the following Locator Strategy :
cssSelector :
"table.table.table-hover.dataTable#orderNoDropdown label[for='thCheckBox']"
xpath :
"//table[#class='table table-hover dataTable' and #id='orderNoDropdown']//label[#for='thCheckBox']"
As you have mentioned it is new window, then you will have to switch to new windows in order to interact with the web element. after reaching to new window you can use this code :
ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles());
driver.switchTo().window(tabs.get(1));
//Now you have focused on new Windows , and you can interact with check box now :
WebElement checkBox = new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.id("thCheckBox")));
checkBox.click();
Then again you have to switch back to page from where you went to this Page, if you want that.
driver.close();
driver.switchTo.windows(tabs.get(0));

Selenium click sometimes not working using Edge driver

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.

How to get a tooltip text on mouseover using Selenium WebDriver

I am not able to get tooltip text after mouseover on icon tooltip. I need to get tooltip text,This is html code.
<a class="tooltip" onclick="SocialAuth.showOpenIDLoginWindow('google');_gaq.push(['_trackEvent','LoginForm','google-login','google login was clicked']);" href="javascript:void(0);"><span>We dont store your password or access your contacts on your Google account.</span><img class="social" height="39" width="40" src="/images/login/google.png"/>
The method to get text from a tool tip differs from a HTML one when its a Jquery ToolTip.
getAttribute() does not work when its a Jquery ToolTip. If you see the tooltip example at http://demoqa.com/tooltip/ , its a jquery tooltip.
Following code works here:
WebDriver driver=new FirefoxDriver();
driver.get("http://demoqa.com/tooltip/");
WebElement element = driver.findElement(By.xpath(".//*[#id='age']"));
Actions toolAct = new Actions(driver);
toolAct.moveToElement(element).build().perform();
WebElement toolTipElement = driver.findElement(By.cssSelector(".ui-tooltip"));
String toolTipText = toolTipElement.getText();
System.out.println(toolTipText);
A good reference is:
http://www.seleniumeasy.com/selenium-tutorials/how-to-verify-tooltip-text-with-selenium-webdriver-using-java
Use the below line of code for fetching the tool tip text from the Element.
String toolTipText = driver.findElement(By.id(element's id)).getAttribute("title");
You have to use Actions for this. in this am printing the mouse hover message in Google
Actions ToolTip1 = new Actions(driver);
WebElement googleLogo = driver.findElement(By.xpath("//div[#id='hplogo']"));
Thread.sleep(2000);
ToolTip1.clickAndHold(googleLogo).perform();
Perform mouse hover action using 'clickAndHold' method.
Get the value of Tool tip by using 'getAttribute' command
String ToolTipText = googleLogo.getAttribute("title");
Assert.assertEquals(ToolTipText, "Google");
Thread.sleep(2000);
System.out.println("Tooltip value is: " + ToolTipText);