Can't spy on CheckListBox with AutoIt - python

I can't spy on CheckListBox object (I think Delphi) in a window frame with AutoIt. It can't see anything in the area. I need to get the list of items from the area and possibly select one the items.
I am using python and robotframework.
I also tried using ControlListView:
self.get_autoit().ControlListView("Setup - XXXXX", "Select the XXXX", "[CLASS:TNewCheckListBox; INSTANCE:1]", "GetText")
But it throws:
com_error: (-2147352561, 'Parameter not optional.', None, None)
The error seems to be an issue with pywinauto.
Anyway I can not get the list of items from this annoying object.
The result from autoit spy is in screenshot:
Can anyone please suggest a good way to access the list of items in this unidentified area?
I can see the inside items from inspect.exe:

Please see the detailed answer from Vasily in the comments. However to summarize:
In the original question, I was trying to get the list of items from CheckListBox using pyautoit however as it was not working. So, as suggested by Vasily, I used pywinauto (another automation tool) in UIA mode and following worked for me:
self.Wizard = Application(backend="uia").connect(title = self.installerTitle) #connect the application
self.Wizard.InstallerDialog.TreeView.wait('visible', timeout=150) #wait for tree view to load
items = self.Wizard.InstallerDialog.TreeView.children() #get the children of tree view
for item in items: #iterate through items, radio button in this case
if item.window_text() == "item_name_to_select":
item.click_input() #click radio button if the text is what we are looking for
return
print "no item found with name: item_name_to_select"
The most helpful trick was to use print_control_identifiers() method in pywinauto to get the identifiers of the control. Also the inspect.exe in uia mode helped in identifying the objects.

Related

Selenium find element with variable value

i want to click an element with a value, which will be inserted by user. I tried this:
def transition(action, value=none):
if (action=='next_page'):
button = driver.find_element_by_link_text('"value"')
button.click()
transition('next_page', value='car1')
The problem is that 'car1' value isn't inserted. What can i fix it?
What your code does, is actually calling the find_element function with the string "value", as you wrote it in quotation marks, making it a string literal
button = driver.find_element_by_link_text('"value"')
What you want to do is insert the name of the variable value without any "double" or 'single' quotation marks, like so.
button = driver.find_element_by_link_text(value)
As you are having a hard time dealing with such simple python syntax, I recommend you first learn the bare basics of the language before trying to write applications with it. There are a lot of free resources out there.
I can recommend W3Schools as a website with text and interactive examples or if you are more of the video type of learner, I can recommend the course by freeCodeCamp.org or a video series by Tech With Tim. Though the last one didn't age really well.

Using "contains (text)" to find parent and following sibling in selenium with Python?

So I'm trying to build a tool to transfer tickets that I sell. A sale comes into my POS, I do an API call for the section, row, and seat numbers ordered (as well as other information obviously). Using the section, row, and seat number, I want to plug those values into a contains (text) statement to in order to find and select the right tickets on the host site.
Here is a sample of how the tickets are laid out:
And here is a screenshot (sorry if this is inconvenient) of the DOM related to one of the rows above:
Given this, how should I structure my contains(text) statement so that it is able to find and select the correct seats? I am very new/inexperienced with automation. I messed around with it a few months ago with some success and have managed to get a tool that gets me right up to selecting the seats but the "div" path confuses me when it comes to searching for text that is tied to other text.
I tried the following structure:
for i in range(int(lowseat), int(highseat)):
web.find_element_by_xpath('//*[contains (text(), "'+section+'")]/following-sibling::[contains text(), "'+row+'")]/following-sibling::[contains text(), "'+str(i)+'")]').click()
to no avail. Can someone help me explain how to structure these statements correctly so that it searches for section, row, and seat number correctly?
Thanks!
Also, if needed, here is a screenshot with more context of the button (in cases its needed). Button is highlighted in sky blue:
you can't use text() for that because it's in nested elements. You probably want to map all these into dicts and select with filter.
Update
Here's an idea for a lazy way to do this (untested):
button = driver.execute_script('''
return [...document.querySelectorAll('button')].find(b => {
return b.innerText.match(/Section 107\b.*Row P.*Seat 10\b/)
})
''')

find text box by web driver python

I'm new in python, web driver in particular and I'm trying to find a text-box - the source code looks like this :
I've tried this :
box = driver.find_element_by_class_name('_3F6QL._2WovP')
though no success.
I'll be happy to add more information if needed - as I said I'm new here. appreciate the help
The problem you have, I think, is that the class is compound - comprises of two classes: _3F6QL and _2WovP.
Selenium doesn't allow for finding elements by a compound class name.
Try this:
box = driver.find_element_by_xpath("//*[contains(#class, '_3F6QL') and contains(#class, '_2WovP')]")
or:
box = driver.find_element_by_xpath("//*[contains(#class, '_3F6QL') and contains(#tabindex, '-1')]")
(Not sure about the latter, though).
Also this should work:
box = driver.find_element_by_xpath("//*[contains(#class, '_1Plpp')]/div")

Creating menus using wxpython

I created a menu using:
fileMenu = wx.Menu()
fileMenu.Append(ID_NEW, "&New\tCtrl+N", "Creates a new file")
I can access New by clicking it on the menu or by clicking Ctrl+N.
My question is: What is the & stand for?
if I delete it everything is still working. However all guides still use it and none of them explain what is the purpose of it.
I've read also here:
http://wxpython.org/Phoenix/docs/html/MenuItem.html#MenuItem.SetItemLabel
"An accelerator key can be specified using the ampersand & character ... Optionally you can specify also an accelerator string appending a tab character \t followed by a valid key combination"
So according to this there is no need to use & if I use \t.
can someone confirm if my conclusion is correct? I just can't figure why I always see both... there has to be a reason why everyone are using it this way.
The & characters in menu titles indicate an accelerator that you can press while the menu is open to quickly access the item. This only works when the menu is open and focused. You'll see the underscored character in the item title as a mnemonic. Same applies to the top level menu entry as well, such as 'File' or 'Edit': by standard WIMP convention you can open said menu using Alt-F (if F is the accelerator for File) and then just as quickly press 'C' if there is an accelerator for C in that menu. Quick and very little known these days.
The \t means a tab in traditional context and in menu items it will make a global shortcut in your frame that you can press without the menu being active.
The shortcut letter following & will be accessible only from the menu.
The \tCtrl+N is available from the entire app, and the short-cut is displayed next to the menu item.

Changing the title of a Tab in wx.Notebook

I'm experimenting with wxPython,
I have a tabbed interface (notebook) and each tab is basically a file list view (yes, I'm trying to make a file manager)
The file list inherits from wx.ListCtrl, and the tabbed interface inherits from wx.Notebook
I'm just starting .. and I had it so double clicking on a folder will cd into that folder, but I want to also change the title of the tab.
How do I do that?
I have the object that represents the file list and the title I want to set it to,
[ EDIT Notebook.SetPageText() takes a number, so I can't pass the tab object directly to it ]
my current approach is to cycle through the tabs until one of them matches my tab:
for tab_id in range(self.GetPageCount()):
if self.GetPage(tab_id) == tab:
self.SetPageText(tab_id, title)
break
This seems rather naive though, isn't there a smarter approach?
I don't know wxPython, but I assume it wraps all the methods of the C++ classes.
There is wxNotebook::GetSelection() which returns wxNOT_FOUND or the index of the selected page, which can then be used to call wxNotebook::SetPageText().
Or use wxNotebook::GetPage() with this index to check whether it is equal to tab.
I think doing something like this helps :
notebook.get_tab_label(notebook.get_nth_page(your_page_number)).set_text("Your text")
If you want to have a reference to the current tab always, you must connect the "switch-page" signal, and save the page in a variable.
As .GetPage returns a wx.Window, I think tab.Label = title should work.

Categories

Resources