How to use auto suggest text box in selenium? - selenium

Code I found on net for the same is :
driver.findElement(locator).click();
driver.findElement(locator).sendKeys(value);
driver.findElement(locator).sendKeys(Keys.TAB);
But I don't know which value I have to enter and what is Keys in 3rd line

driver.findElement(locator).click();
driver.findElement(locator).sendKeys(value);
driver.findElement(locator).sendKeys(Keys.TAB);
driver.findElement(locator).sendKeys(Keys.ENTER);
You have to enter a value to suggest from text box.
Ex: If you need to suggest your state, you can enter state name first letters.
Then the "key" mean selenium webdriver command. you can specify which key should press.
Ex: Manually you have to enter the value and press down arrow twice and press enter.Like this you can specify the keyboard keys.

Related

How to add text in pop up window in selenium

I am trying to test a website using selenium(with java). On my website, there is an option to add a new class. When we click on the add new option button, a pop-up window will come and we can enter our new class name. But using selenium I cannot enter alphabets into the pop-up window. I can only enter numbers in that field. The field accept both alphabets and numbers when we enter the data manually. How can I add alphabets to the pop window in selenium?
Here I attach my code below :
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[#id=\"modal-add\"]")));
driver.findElement(By.xpath("//*[#id=\"class\"]")).sendKeys("LKG");
driver.findElement(By.xpath("/html/body/section/div/div[3]/div/div/form/div[2]/button[2]")).click
screenshot of the field - Class_field_screenshot
As mentioned above you are not able to add alphabets in textfield using sendkeys function. I haven't heard this type of issue before please confirm that either that field accept alphabets or not. if that feild accept alphabets then try using another way like javascript executor to send text as mentioned below
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("$('#id').val("sendtext")");
Can you try Clipboard class for copy and paste string value in class field ? Make sure you click first in class text field and then use paste code. As you say by keyboard you are able to enter alphabet so try to use keys class too.In both cases your keyboard is going to use so may be it helps.

Pressing enter key then inputting a text on a single line or condition

Inputting a text then pressing the enter key on a single line or using a single statement if possible .
tried separating the input of text and the pressing of the enter key
tried this but is it possible to make it just one statement?
WebElement department = driver.findElement(By.xpath("//input[#class='txtdepartment txtenter_event']"));
WebElement department1 = driver.findElement(By.xpath("//input[#class='txtdepartment txtenter_event']"));
department.sendKeys("10");
department1.sendKeys(Keys.CONTROL,"a");
Code
WebElement department = driver.findElement(By.xpath("//input[#class='txtdepartment txtenter_event']"));
department.sendKeys(Keys.chord(Keys.CONTROL, "a"), "10");
I want to input the 10 first before the keys.control or pressing enter key
sendKeys method accepts variable number of arguments of type CharSequence
You can use
department.sendKeys("10", Keys.ENTER)
Or
department.sendKeys("10", Keys.RETURN)
Selenium will send the key sequence as first argument, followed by second and so on...
Java Documentation
You can just send them one by one. (I changed it to python code :) )
department = driver.find_element_by_xpath("//input[#class='txtdepartment txtenter_event']")
department.sendKeys("10")
department.sendKeys(Keys.CONTROL)

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'

Selenium: delete contents from a textbox

Through selenium. how to delete contents from textbox.
I have to delete the last 2 characters from text box using selenium command.
Ex.ABCD to AB.
Try this -
selenium.type("text_box_object", "ABCD");
selenium.typeKeys("text_box_object", "\b");
selenium.typeKeys("text_box_object", "\b");
The keyPress event of selenium can be helpful:
selenium.sendKeys("text1", "ABCD");
selenium.sendKeys("text1", "\b");
selenium.sendKeys("text1", "\b");
This will Click Backspace key twice.
Read the current value and store it as a variable. Then 'Type' out the value that you want in the target field (using a substring of the stored value).
For firefox, the backspace event works only if you setCursorPosition at the END of the text in the textarea, otherwise the typeKeys event will type at the begining of the text.
Click onto it, hit end key and backspace twice

SAS EG dynamic text field

is there a text field control in SAS EG ?
how can i set the selected prompt value ( parameter) into a text field(header is ok too) that will show in the report?
sorry , im new in SAS , so those term im using might not be the correct one.
It is possible to add prompted value to a header.
First go to the Prompt Manager under View menu
Click Add to create a new prompt
Give your prompt a name eg. HeaderText and a display text like Text to display in report header. In the second tab, make sure it's of the type text.
Open the properties (NOT modify, but bottom option of the right click) of the report you want your text to be displayed in.
Go to the prompts screen and add the prompt you just created and click OK.
Now open the modify window of the report.
Go to the titles screen, disable Default Text and enter &HeaderText. in the text field.
Run your flow. It will prompt for a text and that text will be printed in the header.