Using sendKeys() without clicking on element in Selenium - selenium

I want to input a string then format it using Cleditor. However, when I clicked on the B icon then clicked back on the text area frame to input the text, it lost the bold effect. Then I found out that if I clicked on the B icon, then input the text immediately WITHOUT clicking back on the text area frame, the text would be bold.
Unfortunately I use sendKeys() right after the clicking on B icon code, so it clicks on the text area frame and lose all the bold effect. Here's my code:
clickElement(driver.findElement(By.xpath("//div[#title='boldText']"))); **//click on the bold icon**
**//switch to the textarea frame**
clickElement2();
driver.switchTo().frame(0);
Thread.sleep(1000);
new Actions(driver).sendKeys(driver.findElement(By.xpath(".//*[#class='cleditor-content']")), "abc").perform();
Is there anyway I can input the text without clicking on the text area? Any solution will be appreciated.

As I suggest before in the comments, try to input the text, highlight it and then click the B (bold) button.
Example of that in C# code (should be pretty similar in Java):
var actions = new Actions(WebDriver);
actions.SendKeys(< yourElement >, "your text").KeyDown(Keys.LeftShift).SendKeys(Keys.Home)
.KeyUp(Keys.LeftShift).Build().Perform();
boldButton.Click();

Related

Selenium: how to handle dropdown overlapping that is preventing from clicking on to next element

I'm trying to select a list option from the dropdown by sending text (ie; one of the option is: "MyName") to search bar for the dropdown option, (typeAheadInputSelection). After enter the text the selection is typed on the search bar and option is highlighted, however, the highlighted drop down list does not disappear after hitting enter button.
I'm able to type text and press enter (or tab) however, the selected dropdown overlaps and unable to move onto next web element to take actions.
I have tried below code:
IWebelement webElement= driver.FindElement(By.Id("userType");
webElement.SendKeys("name" + Keys.tab)

How to get an export value of the radio button group in acroforms using javascript?

I am making a fillable pdf for a questionnaire in pdf. I have to use radio buttons in the questionnaire. I used the below code snippet to get the value of the radio button group, but it gives me either a null exception or return blank.
I tried a simple code in a blank pdf with just one group of radio buttons with two options and a button.
The code is shown below, where "Group1" refers to the radiobutton group:
var choiceVAL = this.getField("Group1").value; app.alert(choiceVAL);
On clicking the button, the code keeps giving me an exception. I checked all the forums, and this is the code snippet that is used everywhere. I have set the export value to "Y" and "N" respectively.
Can anyone help me with this??

Display Gibberish in VBA ListView (instead of Hebrew, Cyrillic, Arabic, Chinese, Japanese, Greek)

I've created a listview in VBA userform. The Listview showing the data inserted by user in 3 text boxes (after clicking on 'save' button). The user may insert text in hebrew, but in the listview the text is shown as Gibberish (see screenshot in the link below).
Please your help to show the Hebrew text in the listview.
The code of 'save' button:
Private Sub CB_Save_Click()
Set Item = ListView2.ListItems.Add()
counter = counter + 1
Item.Text = counter
Item.SubItems(1) = T_Problem.Value
Item.SubItems(2) = T_ItemT.Value
Item.SubItems(3) = T_ActionDesc.Value
End Sub
Do the following:
Select the ListView in Developer Mode
Press F4
Press Fonts
Select Script > Hebrew
Ok
Try this (taken from spreadsheet1.com), originally written to support Chinese but works all the same for Hebrew
Open Control Panel
Click Region
Click the Administrative tab
Click the Change system locale button Select which language to use when displaying text in programs, such as VBE, that do not support
Unicode. The setting will affect all user accounts on your computer.

Selenium, using xpath to click a button with a similar content

I want to click a button that contains "Add" as text.
ie:
driver.find_element_by_xpath("(//a[contains(text(),'Add')])").click()
however it's not practical to do this:
driver.find_element_by_xpath("(//a[contains(text(),'Add')])[1]").click()
It would be fine, except the page has a button with text "Add User", and it clicks that instead. Is there a way to only click it if it is EXACTLY "Add" and not just contains "Add"?
You can also try :
driver.find_element_by_link_text("Add").click()
link text will match links who's text equals Add and it doesn't match text which contains Add as part of it.
This should work for you:
driver.find_element_by_xpath("//a[text()='Add']").click()
You should change your xpath to require an exact match instead of a partial match.
driver.find_element_by_xpath("//a[text()='Add']").click()
Using text()= requires the text on the button to be equal to 'Add' and will not find other buttons that happen to contain the text 'Add'

How to Double Click on plain text in webdriver?

I have moved mouse pointer on to a certain plain text (a word) by this:
Robot robot1 = new Robot();
robot1.mouseMove(430,628); //location of the text/word
Now I just need to double click so that my text/word gets selected. Can you help me on how to do that?
I tried action builder without element ID (as it is a plain text) for doubleclick, which does not work.
This is exactly the case for Selenium Actions:-)
new Actions(driver).doubleClick().build().perform(); //clicks on the current mouse position
However it would be nicer if you could specify the element which you want to click on
new Actions(driver).doubleClick(driver.findElement(By.id("id")).build().perform();