How to handle dynamic text with no div tags and no info where they are coming from in Selenium? - selenium

I have registration form for which I am trying to create a script.If we don't enter any value in any of the fields and click submit, it is showing a dynamic error message that "Please fill out this field!"
There is no div tag for this text. Moreover, if we click anywhere on the screen, it is disappearing. Can anyone tell, how to read this text?
Thank you.

When the field is marked as required, the Browser shows the message when the form is submitted. There is no way available for you to access it.
You can handle it within your test code by checking that all required fields are entered before submit is called.

Related

Check some field before opening confirmation box in ODOO

I want to check that if some fields in the form view has been checked or not. If they have been checked then show a confirmation message and if not then a error message saying that those fields must be checked. For this functionality I have created a button which calls a specific function in the model. The button has also attribute confirm which enables the confirmation pop up box. But all the time it first opens the confirmation message and then the checking for the fields. I want to have the other way around how to achieve this. Please help.

Selenium: How to get text without clicking on tab?

I'm trying to find text that is located on a specific tab. For some reason the text is available in the html but when I use the command driver.find_element_by_id('hand-graph-title-overview').text without clicking on the 'Overview' tab it returns a empty string. However, when I do click on the 'Overview' tab it will return 'Unpaired OOP' successfully. Does anyone know how to get the text without clicking on the tab?
Images of what I'm trying to scrape.
https://i.stack.imgur.com/9nSc0.png
https://i.stack.imgur.com/MyvDA.png
Maybe try and get the 'value' attribute of the element.
driver.find_element_by_id('hand-graph-title-overview').get_attribute('value')
The answer is no. You can't access the element from the other tab without focusing on it. Retrieval of text is totally based on the presence of the element on the current page. When you click on tab then automatically it gets loaded in the dom and then only you can access the element.

Selenium/Rendering Issue, can't read text from input field

I tried to read the text from an input field of a Wicket App, but I failed. The expected text is displayed in the browser, but it is not displayed in the DOM when I open the developer tools in chrome and inspect this field.
The expected text "Profilname_1562052971" is displayed as you can see in the left column of the screenshot, but I can't see this in the DOM (center column). When I have a look at the properties (right column) of this input element, I see value: "Profilname_1562052971", which is what I expected. Why isn’t it displayed in the DOM?
The truth is it probably is in the DOM you just see it as value name="data:name" this comes from the form. The reason you don't see it in the DOM is that the value is inputted by the user and it is added to the attribute value but this is not saved yet into the DOM! When you save this form it will be added.
To validate it with Selenium use element.get_attribute("value").
See jquery API.

How to validate the optional field?

As per the requirements, "XYZ" field is mandatory field, but this field is optional in the form which I am testing.
"XYZ" is a text field. So when I automate the form, whether that field is empty or filled it passes. In reality, this test should fail.
I am using TestNG and selenium.
Thanks!!!
Leave the text field empty, click on Submit to submit the form.
Check for any validations "Please enter text here." or "1 missed field".
if the the validation alert is not seen, the test script will fail and that is how you will catch it.
Think of selenium as a way to replicate a real user click through on a website. So when manually clicking through, you clicked to submit the form and went to the next page when you actually expected a validation alert.

Cannot click Submit button on Selenium IDE

I am having trouble getting Selenium IDE to click the Submit button on one of my webforms after having selenium open and fill out the form. I am using the clickAndWait command and identifying the button by its ID:
<td>clickAndWait</td>
<td>id=ctl00_ContentPlaceHolder1_OSVFHResults_btSave</td>
<td></td>
Interestingly, if I write a script that simply opens the form and clicks the submit button without filling it out, I am not having any problems. My problem is coming specifically after I've asked Selenium to fill out the form. Additionally, if I try to manually click the submit button, it doesn't work if the Selenium script to fill out the form was run before my manual input. If I manually open and fill out the form, I have no problems clicking submit, and Selenium works for all of the other form's submit buttons on the site. Anyone have any ideas?
Instead of filling form with type command you can try typeKeys one. It simulates keystroke events on the specified element, as though you typed the value key-by-key and probably enable your submit button.
It sounds like some javascript event unrelated to click() (such as mouseover or onkeydown) is attached to one or more of the form fields and is responsible for enabling the submit button.
You'd have to look at which exact events are being fired, either by looking at the source with something like firebug, or by using a javascript debugger. Then modify your Selenium script to make sure the same events get triggered.
After type the values in the form just try "ClickAtandWait" instead of "clickandWait"..i also face the problem once and it gave hands once..
selenium.clickAtandWait("locator", "position");
if you know the exact "position" just put it, otherwise leave it as an empty string.