retain element values selenium chrome python - selenium

I am using selenium-chrome webdriver for logging into a website.
In Page -1 , I am selecting values for multiple fields (includes text fields/drop down etc) and click submit on page 1. This opens page2 and by clicking on 'Generate button' - it downloads an excel file.
Now i need to go back to Page1 and change JUST one value of a drop down field in page 1 and generate another file (same process).
But problem I am facing is, after coming back from Page2, values which were already set in Page1 is refreshed /lost.
How can i make sure, earlier values are not lost, during this process.
Thanks in advance.
Regards,

As you are logging into a website, selecting values for multiple fields and clicking on submit button on page 1 which opens page2; here the page changes. So the DOM tree also gets changed. Selenium is now having the focus on the new HTML DOM. WebElements of the new DOM are attached now. So essentially the WebElements of the previous page are no more attached to the current DOM.
Now as you go back to Page1 and and try to find/search the same values which were already set earlier you will face a StaleElementReferenceException. All you have do is again fill out the fields (text fields/drop down etc).
Here is the official documentation on StaleElementReferenceException

Related

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.

Using puppeteer to automate button clicks for every button at every URL in a web app

I am currently trying to use JS and puppeteer to take a screenshot of every url in my web app, as well as take a screenshot of every button that can be clicked. Is there a way to click each button without specifying the id? Not all of my buttons have an id and even if they did, I wouldn't want to have x number of page.click(id, options) for each button I have (which is quite a lot).
Thanks
I have tried going based off each className (this app is built using react) but this does not work. It will take a screenshot of the same buttons over and over. I believe because if page.click has multiple of the same options, it only chooses the first one and many buttons have the same styling classNames.
You could get an array of each element on a page, go through the elements with a for loop determine if it is a button, then click it. Then for each page you'd have to input each url in an array and then use a for loop to go through it.

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.

PDF creation with page refresh

I have a page with a viewPanel and a dialog. When an item in the viewPanel is clicked, the dialog opens, prompting the user to make changes to that item, and offering them the option to generate a report of the item in PDF format.
At first, I tried putting the PDF creation onto a button, as described here: http://www.eknori.de/2011-10-25/xpages-to-pdf-with-itext/ However, whenever the button is pressed, I get a "NotFoundError: DOM Exception 8" which seems to stem from the dojo JS. So currently I have an alternative whereby the button simply sets some sessionScope variables and opens a pdf.xsp XPage, where the variables are read back and the PDF is created.
The PDF gets created correctly, but it also means that the page that the user is on won't be refreshed to display their new change in the viewPanel. I've tried adding page redirects at the bottom of the XPage which creates the PDF, but with no luck.
So, how can I create a PDF and prompt a user to download it, but also refresh the page that they are currently on?
Are you isseuing an partial refresh on the button to hide your dialog and to execute the code for pdf generation? If so you I think that there is your problem. What you could do is to do a partial refresh on the onClose() method of the dialog to refresh the viewpanel. In the clientside onunload method you could open a so called xAgent which renders the pdf for you in a new window (window.open(pdf.xsp?docid=xxx). Take a look here: NotesIn9: 039 Creating PDF’s with XPages Part 2
Of cours the problem with this approach is that when you have a button / image in yoru viewpanel row that displays if the report has been created is not shown because the xagent runs after the / during the time the viewpanel row is being refreshed.

Dojo Date text box and history.back() function

Here is the flow:-
page:-1 select Date from dojo DateTextBox and submit the page. There are couple of text fields along with date text box.
page2:- Review the values submitted in Page1. Have a option to go back using javascript History.back()
Problem:- when I go back other text boxes preserve their values but dojo DateTextField not able to prepopulate with the original value.
How I make the dojo component to remember its value when History.back() gets called?
I know History.back() function render the page from browser cache.
Thanks,
Manoj
The text boxes are remembering their values as a feature of the browser. The Dijit won't do this because the browser doesn't know anything about it. You would have to write custom code and remember the setting via a cookie and set the widget to the value of the cookie on page load (or on widget instantiation).