Selenium Automated Testing and java textboxes - selenium

Hey Ive tried looking for how to solve this for a couple hours and I keep coming up blank.
Im using Selenium IDE to try and make a few simple Automated tests (basically the test will access the site, create content and submit it, to ensure that it still works)
But there is a part of the site that is a javascript text box and i need to enter text into it.
However Selenium doesn't recognize any actions I make inside the text editing section of the box. It will recognize if I press something like BOLD or ITALICS.
When I select BOLD it returns: click | //a[#id='mce_editor_1_bold']/img |
But like i said, it wont recognize when I select the text editing part of the box.
I tried using xpath (and firebug) after some research online, but I cant seem to make that work.
Anybody have help or ideas to offer?

You can also use javascript to work with Selenium. So for example, if your rich text box has id="RichText" you can obtain the element via javascript and input your value there.
The code looks something like this:
| verifyEval | javascript{this.browserbot.getCurrentWindow().document.getElementById('RichText').value = 'Foo Bar'} ||
However, I've found that the syntax can vary for the this.browserbot portion. It will take a bit of work to get things going. You can also checkout this article from The Automated Tester which has information on what you're trying to do.
Also this question should help you out further: Selenium: How do I use javascript to clear a value from a form field?

I would recommend persevering with Firebug. Open the page that your testing and use Firebug's 'Inspect' feature to locate the text box in the HTML source. Then you should be able to find a way to locate the box using id, xpath, or css.
For example:
If it has id='textBox' you can locate it using id=textbox.
If it has class='jsTextBox' you can locate it using css=.jsTextBox
Otherwise you can use XPath - I'd recommend getting the XPath Checker extension so you can right click the text box and find out the XPath. You might want to play around with the result to make it a smarter XPath though.
Once you've found out the location you should be able to input data using the type or typeKeys commands. type changes the value, and typeKeys fires key up/down for each character - it's slower but sometimes needed depending on the application under test.
type | id=textBox | myValue
verifyValue | id=textBox | myValue
Hope this helps,
Dave.

Related

VBA to find if an element contains certain texts

I'm new to Selenium and VBA.
What i want to do is automate selection of a certain TEXT in a CSS.
Selenium brings me this:
css=.x-grid3-row:nth-child(42) .x-grid3-col:nth-child(4) > .x-grid3-cell-inner
Everyting would be fine, except the TEXT I want to select sometimes move to different grid3-row:nth-child
What I want to achieve is to find in which x-grid3-row:nth-child the desired TEXT is so I could click it with a VBA bot.
Thank you for your help.
You won't be able to construct a css-selectors passing the desired text.
You can find a relevant detailed discussion in selenium.common.exceptions.InvalidSelectorException with “span:contains('string')”
As an alternative you can use a xpath based Locator Strategy as follows:
driver.FindElementByXPath("//*[#class='x-grid3-cell-inner' and text()='certain_text']")

Click not working on combo-box down arrow button karate UI testing

I tried clicking on down arrow button for a Combo Box (Select is not available. Its a React JS application and once I click on arrow button only list shows selection items) using below karate command but click not happened in application and no error displayed. [The same xpath worked in selenium click command,and showing unique item on Inspect search]
And waitFor("//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div")
And click("//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div")
Note: Then I tried below command
And assert('//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div').exists
and got error
javascript evaluation failed: assert('//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div').exists, :1:19 Expected , but found root
assert('//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div').exists
It would really help us if you follow this process, it is simple and should not take much time for you to give us a small snippet of static HTML (or you can mix react if really needed).
https://github.com/intuit/karate/tree/master/examples/ui-test
EDIT: you also seem to have mis-matched single and double-quotes in your code.
Also note that you should be able to fire a JS event or click by using the script() API. See this example: https://github.com/intuit/karate/tree/master/karate-core#script
So this is an alternate approach to be able to overcome any tricky situation that comes up.

How can I get the XPath expression from a web site's HTML content?

I want to use XPath expressions in Selenium code, but I don't know how to get it from a site's HTML code.
I'm using the Google Chrome web browser.
The easiest way is to inspect the element you want to get the XPath expression for. Then click on the highlighted code and Copy → Copy XPath which give you a full XPath patch you can copy to your code.
For Firefox, you should install Firebug or another extension like this.
As neliCZka suggests, you could also try to build a relative path if its possible by trying to find the proper XPath in the search bar in Chrome after inspecting the element.
I see that someone has downvoted the suggestions to use the Copy XPath option from different inspection tools. That's probably because these paths can often be difficult to maintain as the application changes, won't work in Selenium because they're not sufficiently unique, or can just be unreasonably complex for complex HTML.
Copy XPath... is useful as a starting point though. If you're not familiar with XPath, this tool can help you to get a better feel for how to apply it to your HTML content, but it's very important to learn how to use XPath yourself.
Right click on the element you want to have an XPath expression for, and then click Inspect Element. A new frame will open with the HTML source code.
Now right-click on the code and select "Copy XPath".
Note: you will have to remove " WITH ' after copying it into your code
Install Firebug for Firefox. ...
Open the website that you want to inspect. ...
Click the Firebug button. ...
Click the element inspector button. ...
Click the web page element that you want to inspect. ...
Right-click the highlighted code in the Firebug panel. ...
Select "Copy XPath" from the menu.
You can press F12 to get the check page, select your hoped HTML code, and hit the mouse 2. It has the copy option, and there is a copy XPath.

Sikuli integration with Selenium WebDriver

Can anyone tell me how to work with multiple edit boxes using Sikuli integrated Selenium WebDriver.
For example, I have 2 edit boxes which are labeled as username and password. So I want to click on the 1st edit box, then enter values and again want to click on the 2nd edit box. The size of the two edit boxes are the same. So how sikuli integrated Selenium WebDriver will identify which edit box to click.
If you are referring to the SikuliWebDriver, then this link has an example on the usage http://code.google.com/p/sikuli-api/wiki/SikuliWebDriver.
I would rather prefer using the Sikuli Java API and create wrapper functions around the Sikuli functions like click, type etc. This API is in active development and has good support available.
http://doc.sikuli.org/faq/030-java-dev.html
You can use the offset functionality. ie, you do not only use an image of the text field, but use a region of the screen which identifies something related to the text fields.
You may select a large rectangle which includes a heading above both fields, then use offset x/y coordinates and move the little crosshair over the exact location you wish to click/type.

How do I make a Selenium test for a page with a textbox whose name constantly changes?

I am trying to create a test that can enter a username and password into a login form on a page. However, the textbox name changes on every load of the page, and so the test stops each time I run it.
How can I set up Selenium IDE so that it can identify the text box across refreshes?
I am assuming that the textbox only changes part of the ID and not the entire ID each time.
To work with this I would recommend using xpath like people have put above but make it more robust in that it only find that element each time.
e.g.
//input[contains(#id,'thePartOfTheIdThatNeverChanges')]
or
//input[starts-with(#id,'thePartOfTheIdThatNeverChanges')]
or
//input[ends-with(#id,'thePartOfTheIdThatNeverChanges')]
//form1 (3) - First form element in the HTML
Pulled from here as an example This is making use of XPath. In theory you can make use of XPath to focus on parsing the structure of the XHTML, however this is fairly fragile, so it's not necessarily a wise thing to do but it should take care of your issue.
Does the location of the text box change, or just the name?
You could use a css or xpath selector to get the text box if it is in the same place.
I would recommend CSS because -
a. for the readability
b. for the ease of access (and, in your case, maintainability).
I use firebug for accessing/formulating the CSS identifier.