Robot framework input text after tab - selenium

Im making a automated test but the input fields doesn't have any specific id and classes. I don't want to select everything by using xpath so i thought i was going to use the Press Keys function. After i put the text in the first input i do the function:
Press Keys LOCATOR TAB
After that i used the tab button, it goes to the next form but how do input text in the form?
I know there is the input text function but it needs the locator for entering text. How can i input text without using the input text locator ?

Try to still take the xpath even if it has no specific id or class, it also works with an xpath like this: // html / body / table / tbody / tr [4] / td / center / form / table / tbody / tr [ 4] / td.
Example Input Text:
Input Text [locator, text, clear = True].
Example Press Keys:
Press Keys, locator, ALT

Related

VBA macro how to click on button on website on chrome, using Selenium

I am trying to program to click on one button on website on chrome. The name of the button is "Add to Cart".
Please see HTML of the website:
enter image description here
And this is the VBA code:
CD.FindElementByCss("div.addToCartButtons clearAfter > button blue right s-addToCart > span.Add to Cart").Click
How can I do this?
Tags are important, you can anticipate some of the events attached to certain element in DOM just by reading its tag.
In your case you can click on the button tag directly instead of clicking the tag span, since this last one rarely has a .click event attached to it.
If you can provide an url to test this website I might help you better. This are the possible approaches:
1) Advanced:
a. Spaces in class are change for dots
b. Requires to understand tag's meaning and relative position of elements in DOM
'Example
'Clicking first button in div using only tag ("button" is a tag)
CD.FindElementByCss("div.addToCartButtons.clearAfter > button").Click
2) Intermedium:
a. Use only first Class and ignore all others after first space
b. Requires to understand what an elemment.child is
'Example:
'Clicking first child of "div" (Everything inside "div" is a child)
CD.FindElementByCss("div.addToCartButtons > button:nth-child(1)").Click
3) Easiest:
a. Double quotes ["] inside querySelector are changed to single quote [']
b. Requires to use Copy JS path in DevTools (Ctrl + Shif + I)
'Example:
'Clicking with Javascript in your website through ExecuteScript
strTemp = "document.querySelector('div.addToCartButtons clearAfter > button blue right s-addToCart').click"
CD.ExecuteScript (strTemp)

selenium send key for xpath not working

I want make automation for this web site
in this web site 3 text box are here check image
1st text box x path is /html[1]/body[1]/div[3]/div[1]/div[2]/div[1]/searchbar[1]/div[1]/div[1]/div[1]/div[1]/form[1]/div[1]/div[1]/div[1]/input[1]
here is my code
driver.findElement(By.xpath("/html[1]/body[1]/div[3]/div[1]/div[2]/div[1]/searchbar[1]/div[1]/div[1]/div[1]/div[1]/form[1]/div[1]/div[1]/div[1]/input[1]")).sendKeys("rio salon");
when I run this code I got this error
Exception in thread "main"
org.openqa.selenium.ElementNotInteractableException: Element is not reachable by keyboard
How can i fix it? I hope my xpath is correct.
The field has aria-hidden=true attribute, so you get ElementNotInteractableException. You need to click on the dropdown first to change the attribute to true
WebElement dropdown = driver.findElement(By.xpath("//*[#id='search-form']/div/div[1]/div/div[1]/span"));
dropdown.click();
WebElement textField = dropdown.findElement(By.xpath("./parent::div/following-sibling::input[contains(#class, 'ui-select-search')]"));
textField.sendKeys("rio salon");
You can click in an input field with a div or span tag, but you cannot type in the field. So, your XPath must be written with an input tag if you want to sendkeys or type in an input field. For example:
//input[contains(#placeholder,'Site')]

Text field values in robot framework using selenium

I am using Robot-framework selenium2.0.
In the robot test I made, it fills out a form and save it. In the form, I have to put some numeric values in some text boxes but somehow the previous\default value of 0.0 is not removed from any of the box. When I run the test normally it puts the values after 0.0. For example I want to put 50 in the box but the test puts 50 after 0.0 so it becomes 0.050 and when it switches to next text box the value becomes NaN.
Here is how I am doing it,
wait until element is visible text_field
click element text_field
input text text_field 50
Is there any ascii codes that can be used to select values (ctrl+a) and delete the values first and then use input text to input values?
You can try:
Clear Element Text text_field
More on this here.
You could also use Selenium directly:
driver.findElement(By.id("text_field")).clear();
This may be work for you:
driver.findElement(By.id("text_field")).click()
driver.findElement(By.id("text_field")).pressKey('Ctrl' + 'A')
driver.findElement(By.id("text_field")).pressKey('Delete')
more Press Key here

Tosca: How to scan Dropdown textbox which disapper upon opening xScan

I have a problem in scanning a drop-down menu which disappears upon opening the xScan. I need to get the module id of the dropdown menu to verify some test steps.
Do you have any solution with this if it is not really possible to get the module id of the dropdown menu?
Open developer tools in your browser of choice (F12), navigate to the console and input the following code:
var fulldoc='';
var scrollX=0;
var scrollY=0;
document.addEventListener("keydown",function(event){
if(event.key=='q' && event.altKey){
fulldoc=document.body.outerHTML;
scrollY=window.pageYOffset;
scrollX=window.pageXOffset;
}
if(event.key=='w' && event.altKey){
document.body.outerHTML=fulldoc;
document.body.scrollTo(scrollX,scrollY);
}
});
When the window looks the way you would want to scan, press 'Alt + Q', then press 'Alt + W'.
Now your window will freeze and then you can scan your page.
To steer the objects you need to refresh your browser.
You can resolve the issue with below 2 steps
1 - Add some text in textbox which will populate the dropdown below it .
2 - Use Send Keys Module to scroll down and select the value.
I had a similar issue where we had a popup that only appeared when clicking on a text box. The solution we received from the Tricentis trainer was as follows:
Part One
1. Open your application in Chrome
2. Right click the inspect
3. In the inspector window, on the Elements tab, navigate to your html element where it should be (you can do that by clicking on the element and check that you can see the html in the element)
4. Use the debugger to add a break point there, this should pause it and you should be able to see the elements you need to steer it.
5. Once you found the element, you will need the type of element (e.g. div, span, etc), and the class name
Part two
1. Rescan your module and select any element that matches the criteria of your element selected in Part One #5
2. Identify it by only it's class name property and tag
3. Save and close
4. Edit the element in the module view by changing the class name. This should help you steer it
Note: if the element class name is not unique, you might need to use Explicit name.
Good luck

Selenium select a text in a not select input

How to select an element in this web element :
this input is a text type and not a select option !!!
Type some characters (or all/none of them) in that input box
Wait until the options appear
Take the identifier (id/XPath/class/CSS/etc.) of that element (option) (maybe it is a div)
F12 in Chrome > click on the magnifier > click on the option
F12 in Firefox/Internet Explorer > click on the arrow > click on the option
Click on that elements / take its content