Selenium: How to get text without clicking on tab? - selenium

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.

Related

robotframework- unable to click a button on a modal dialogue box

when I open a particular webpage it has a EULA form that appears on top of the home page in the form of a modal in HTML/CSS. I have tried the XPath of the accept button but it says element not found also tried using handle alert.
is there a unique way to handle a dialogue box in robotframework?
image of HTML in inspect view
SeleniumLibrary.Set Focus To Element ${button_on_popup_page}
SeleniumLibrary.Click Element ${button_on_popup_page}
I figured it out, shown in the above code. I first set focus to the button and then used the click element. This seemed to work.

How to unfocus from all inputs/elements in Selenium without tabbing out

I have a form where I fill in textboxes through selenium (java). Some of the textboxes dynamically generate extra content when you click on them and remove the content when you focus on something else. This is a problem when I automate because if I am focused on a text box and try to click on something else, when the page removes the content it doesn't register my click and I need to click again. This leads to flakey behaviour since I need to now consider whether I need to click or double click a button depending on what element I was focused on before.
I can't send a tab key to the text box because sometimes it will tab into another textbox that has the same dynamic generation behaviour, leading to the same scenario as before.
I tried clicking the page element but it also doesn't seem to work. I also tried clicking the root div. It just doesn't seem to register my click (I also tried jsclicks)
What I would like to do is have a general way to unfocus a text box after I fill it.
Thanks!

How to handle dynamic text with no div tags and no info where they are coming from in 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.

selenium, hidden button by overlapped input ( not clickable)

Is there any way on how to click a hidden button by an overlapped input text field, for example if you go to www.google.com and enter a text to search for, selenium can not find the "Search Google" button because it is hidden by the autocomplete of the text field.
Thanks.
You can bypass the validation by using #click! instead of #click. Basically, this triggers the click via JavaScript rather than through standard Selenium commands.
browser = Watir::Browser.new
browser.goto('www.google.com')
browser.text_field(name: 'q').set('watir')
browser.button(name: 'btnK').click!
If you are only using Selenium, you can do:
btn = driver.find_element(name: 'btnK')
driver.execute_script('arguments[0].click();', btn)
As discussed in the comments, you could also close the suggestions box before trying to click the button. You can do this by moving focus to any other element - eg the first link on the page. Depending on what you're testing, this may or may not have value.
browser.text_field(name: 'q').set('watir')
browser.link.focus # move focus to any other element so suggestions close
browser.button(name: 'btnK').click

How to get summary validation from multiple tabs in ASP.Net MVC?

I have a multiple tabs in a page and each tab (lets say Menu, Edit, Tools) has a couple of text field. Each field have Required Data Annotation. I have one Save Button to save all the fields from multiple tabs. Now my problem is when I am in Menu tab and without entering anything in the text box and click Save Button I got validation summary. If I move to other tab (Edit tab) without entering anything in the textbox in the File tab and I did the same thing in the Edit tab I got validation summary of the current tab (Edit tab) only but not the other one.
How can I get validation summary from all the tabs? OR
Can we validate while moving from one tab to other?
FYI, Each tab is <a href = "#tab-Menu">
Elements on your non-active tabs are most probably hidden. Bu default after version 1.9 jquery validation does not validate hidden elements (ignore: ":hidden"). You can see discussion here: https://github.com/jzaefferer/jquery-validation/issues/279
To enable validating even hidden elements, use this code:
// This will validate all tabs at once, not just current tab.
$.validator.setDefaults({
ignore: ""
});
More info on what you can specify is here http://jqueryvalidation.org/validate/