I'm using Qwebview with Pyside/Qt to view an HTML page on a GUI I'm working on.
I need the possibility to add a search text function, otherwise it is useless for the purpose the GUI is made.
I've searched but I didn't find anything useful for build a code that search the text and scrolls down the page as it is made in the common browsers.
The only function I found is findText but it returns a boolean and I cannot see how it can be useful.
Do somebody have an hint / advice / guide or code for this request?
Thank you.
Okay, so it turns out that i had an example of this using a QTextBrowser, which has a lot of this built into utility functions.
You can still do it with a QWebBrowser though.
Bind ctrl-f to open a search panel, and then make it so that the search box sends out two signals;
(presuming it's a QLineEdit), returnPressed, and textChanged.
Each of them then calls findText on the QWebPage object.
The important part is setting the correct flag in the findText call (which you'll want to set with checkboxes in your search functionality, i'd say).
You set the flags so that HighlightAllOccurrences is not set.
I cannot see any way to get details on a selection. Are you sure that when you do not set the HighlightAllOccurences flag it does not scroll to the next selection automatically?
Related
Using Selenium to try and automate a bit of data entry with Salesforce. I have gotten my script to load a webpage, allow me to login, and click an "edit" button.
My next step is to enter data into a field. However, I keep getting an error about the field not being found. I've tried to identify it by XPATH, NAME, and ID and continue to get the error. For reference, my script works with a simple webpage like Google. I have a feeling that clicking the edit button in Salesforce opens either another window or frame (sorry if I'm using the wrong terminology). Things I've tried:
Looking for other frames (can't seem to find any in the HTML)
Having my script wait until the element is present (doesn't seem to work)
Any other options? Thank you!
Salesforce's Lighting Experience (the new white-blue UI) is built with web components that hide their internal implementation details. You'd need to read up a bit about "shadow DOM", it's not a "happy soup" of html and JS all chucked into top page's html. Means that CSS is limited to that one component, there's no risk of spilling over or overwriting another page area's JS function if you both declare function with same name - but it also means it's much harder to get into element's internals.
You'll have to read up about how Selenium deals with Shadow DOM. Some companies claim they have working Lightning UI automated tests/ Heard good stuff about Provar, haven't used it myself.
For custom UI components SF developer has option to use "light dom", for standard UI you'll struggle a bit. If you're looking for some automation without fighting with Lighting Experience (especially that with 3 releases/year SF sometimes changes the structure of generated html, breaking old tests) - you could consider switching over to classic UI for the test? It'll be more accessible for Selenium, won't be exactly same thing the user does - but server-side errors like required fields, validation rules should fire all the same.
I would like to know if there is a way to get locator for any text in robot framework ? I am using Robot Framework with Selenium2Library.
Scenario example : Suppose I have message "Hello" on my page and its position keeps on changing when new message appears.I want to click on this "Hello" word to show complete message. How can I do that. Please help.
I've seen locations change a lot with Angular webpages, so I understand what you mean. IDs can be generated anew every time the page loads and may change depending on the order in which you click on elements. Worse, they can affect dom- and xpath-based locators as well. The short answer to your question is no, it doesn't exist within standard Selenium, Selenium2, ExtendedSelenium2, or any other standard library.
The medium answer to your question is solved in my currently-most-advanced Click Element by Text custom keyword. It generates an xpath based on your inputs and if it can be found with a simple text search with no extra parameters, it'll do it. It is testy at times and may require argument injections to work, but in general it works very well and is easy to use when xpaths are remotely possible.
Click Element by Text
# EXAMPLE USAGE
# Click Element by Text "text on the element" id="midlevellocationoftext" button
# NOTE: Does not account for extra spaces at the beginning or end, text must be exact
# NOTE: Allows for injections on purpose to allow user to be more exact with their location
[Arguments] ${text} ${location}=* ${elementtype}=*
Click Element xpath=//*[#${location}]//${elementtype}[text()=${text}]
The long answer is that I'm working on something better. Here's what I know so far. The elements to do this do exist out there in the void. JavaScript can turn a webpage into a list of elements. I can call .innerHTML on those elements to get their text. I haven't worked out the details, but I honestly think it's possible and when I get it figured out, the code will be on Code Review for others to see.
As the title says, how can I .click() a button using Selenium, when the button gets "disabled" after using the method clear or send_keys?
Before:
That's the page status when I open it's url... but then right after I run my code to find the textbox and replace it's value, the element gets disabled (maybe by some sort of JS) right after I clear it's content or write something to it using send_keys.
After:
Code:
txt_value = driver.find_element_by_xpath('//input[#id="txtValor4"]')
txt_value.clear() #this disables the button
txt_value.send_keys(str(123,45)) #this also disables the button
My question is:
How can I bypass this website protection and press the Continuar button?
I thought about disabling JS, but the whole website relies on it to produces the requires documents.. wrong alternative.
So I thought about using the button properties to simulate the pressing of the button... just don't know if it's possible, or how I could do this.
Another option was blocking only the JS that disables the button maybe mapping where the command comes from using the inspect element and network tools...
So is there any way to achieve this?
ps.: I can't give the URL because it requires my login data.
Ok, so you can't directly do this through normal means. Selenium WebDriver is made to simulate real use of a browser. It may be possible however to use the execute_script function. (Java Selenium has a built in JavascriptExecutor class, I assume this is python's version.) The execute_script function allows Selenium to perform tasks that a human interacting with a browser can't do.
driver.execute_script("document.getElementById('buttonid').click()")
Or something along those lines should work. Hope that helps you out.
If you don't get any solution with selenium and javascript, you can use Sikuli concept. To click that element, take the image of the 'Continuar' button and save it in resources folder.
String elementImg=Path of the Image;
screen.click(elementImg);
I could bypass this using driver.execute_script("document.getElementById('txtValor4').value = 123.45"), to pass the values into the textbox, so the button didn't got disabled and I could press the Continue button.
Even bypassing this, the result wasn't the expected! The value that I entered was supposed to be corrected by some sort of interest. But bypassing this, the value isn't corrected.
Today the user that asked the program told me that everytime I change the value inside this textbox, I must press the Calculate button.
So, instead of inefficiently bypassing this disable method, I could solve my problem using:
b = driver.find_element_by_xpath('//input[#id="txtValor4"]')
b.clear()
b.send_keys('123.45')
driver.find_element_by_xpath('//input[#id="btnCalcular4"]').click()
driver.find_element_by_xpath('//input[#id="btnContinuar4"]').click()
This way the tax value is corrected by interest and the website generate the .pdf with the exact value that I was expecting.
Many thanks for everyone that put some time and effort trying to help me.
I've got a text view and a web view, each inside a scrolled window of their own and I'm trying to achieve synchronized scrolling between the two but I can't seem to get it to work.
The web view is basically taking the text from the text view and rendering it as marked up HTML via webview.load_html_string(). I think the problem could be the delay in loading the HTML as every time the web view is refreshed it is scrolled back to the very start.
Right now I call a function every time the content of the text view is changed and then modify the vadjustment.value of the scrolled window containing the web view.
But this doesn't work. Is it because of the delay? I can't think of any way to solve this issue.
why do you want sync those scrollbars? You can achieve this by using the same Gtk.Adjustment (number of pages sets to 0).
I haven't use much of webkit but it essentialy a widget. so maybe a workaround would be disconnect a signal "value-changed" from Gtk.Adjustment until "load-status" signal from WebKitView reached Webkit.LoadStatus.FINISHED (if that's the correct syntax).
If that doesn't work, maybe you use WebKitView.move_cursor () (if i remember the function properly) based on Gtk.Adjustment on your text view (we use 2 adjustments this time)
I have an issue when trying to test a web application with Selenium/Python. Basically I can't test elements of a pop-up window.
A scenario: I can test all elements for a page. But when I go to click on a button that opens up a small pop up box I can't test the elements on the popup. It's like the pop up isn't in focus or active.
I can test elements on the next page. For example click a button, brings me on to next page, and I can work with elements on the 'next' page. So it the problem seems to be popup specific.
I could post code but to be honest it might confuse at this stage. I may post code in a later post, thanks
There is a property called switch_to
Q: How do I handle pop up windows?
A: WebDriver offers the ability to cope with multiple windows. This is done by using the WebDriver.switch_to.window(knownName) method to switch to a window with a known name.
If the name is not known, you can use WebDriver.window_handles to obtain a list of known windows.
You may pass the handle to switch_to.window(handleName)
For example I used driverName.switchTo.window(driverName.getWindowHandle()) to get a hold of popups for which I didn't want to look for names.
Additional references:
http://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions
For the Selenium RC API, you need to use the SelectWindow command to switch to the pop-up window. The window can be specified either by its name (as specified on the JavaScript window.open() function) or its title. To switch back to the main window, use SelectWindow(None).