Pywinauto identifier is Empty - python-3.x

When i print the identifiers of the dialog following is the output
Qt5QWindowIcon - 'b'widget_fenetre_openglWindow'' (L395, T202, R1046,B602)
'b'Qt5QWindowIcon20''
'b'widget_fenetre_openglWindow''
'b'widget_fenetre_openglWindowQt5QWindowIcon''
Qt5QWindowGLOwnDCIcon - 'b''' (L400, T202, R1040, B602)
'b'''
'b'Qt5QWindowGLOwnDCIcon''
there are other identifiers above as well, i need to know what
Qt5QWindowGLOwnDCIcon - 'b''' (L400, T202, R1040, B602)
means, how can i access that element from pywinauto,
or is it some unaccessible element not relevant to ui?

Related

searchbox.send_keys() is unable to write any text on the bar by itself

[from selenium import webdriver
driver = webdriver.Firefox()
driver.get('https://youtube.com')
searchbox = driver.find_element("xpath",'//*[#id="search"]')
searchbox.send_keys("Akram Khan")
searchButton = driver.find_element("xpath",'//*[#id="search-icon-legacy"]')
searchButton.click()]
(https://i.stack.imgur.com/egHm1.png)
The function [searchbox.send_keys("Akram Khan")] have to be write the mentioned text("Akram Khan") inside the search box of YouTUbe.
So the problem is that when you first try to get the searchbox element with the current version that you had it was searching for the first occurrence of an element with id='search' which there is an element that is before not connected to the search box (therefore send_keys() to that element doesn't work). You can get the specific element that you want by specifying the tag that it is with your current code by doing (because the input element is what you want to be sending your response to):
searchbox = driver.find_element("xpath",'//input[#id="search"]')
#id='search' is reflecting to list of elements so use unique element like #name='search-query'

how to use selenium python to open new chat whatsapp (i need to target the second icon New Chat)

I need to target the second icon New Chat but they have the same class name
from selenium import webdriver
driver = webdriver.Chrome('C:/Users/ka-my/AppData/Local/Programs/Python/Python37-32/chromedriver')
driver.get('https://web.whatsapp.com/')
input('Enter anything after scanning QR code')
user1 = driver.find_element_by_class_name('_3j8Pd')
user1.click()
1.i need to target the second icon New Chat
just like Facebook and google the class names are dynamically generated So the best way around that is to look for something constant which is the icon string
new_chat = driver.find_elements_by_xpath('//div[#title="New chat"]') # return a list
if new_chat:
new_chat[0].click()
To get 2nd icon in new chat, you can use this:
# get the 2nd element in the list
second_icon = driver.find_elements_by_xpath("//div[#class='_3j8Pd']")[1]
Or:
# get the 2nd element in the list
second_icon = driver.find_elements_by_xpath("//div[#class='_3j8Pd'][2]")
In first example, we are getting a list of all the div elements, and picking the 2nd item using the [1] index. In second example, we are using element index in XPath [2] to get the second element in the list. List index is 0-based and XPath element index is 1-based, so that is why we see 1 and 2 here.

how to get the value from specific nested class with xpath

im trying to get the value of the class "sum_num" with xpath .i have 4 classes witrh the same name
when i'm running the code, i'm getting the value '0' or the value for the 3rd class, which is the span text - "lblPrice1"
the class "sum_num" is exsiting 4 times in the pages
but i need only the value or the 2nd one.
how to get only the 2nd value from the class "sum_num" " ?
and more - is this the best way to crawl a web page ?
python (i have tried both option):
cost = product_link_selector.xpath('//div[./div/#class="product_code_price"]div/div/div/#class = sum_num/text()').get()
cost = product_link_selector.xpath('//*[contains(#class,"item_sum_group product compare_main")]//*[contains(#class, "sum_num")]').get()
You can use the index to get the 2nd item. Here is the sample code for using the index.
(//*[#attribute='attribute_value')[index]
Try with the below.
product_link_selector.xpath('(//*[contains(#class,"item_sum_group product compare_main")]//*[contains(#class, "sum_num")])[2]').get()

ie getelementsbyID with same ID

i have a script that works with internet explorder (ie) and i need to loop the select fields, that it zelf is no ploblem bu the 4 elements got the same ID (on the same page).
How do i let it loop through the 4 fields?
Can i make them more spesified?
the code i use is the following:
ie.document.getElementByID("DownloadImage").Click
The ie code is the following:
field 1
<a id="DownloadButton" href="javascript:__doPostBack('ctl00$ctl00$MainContent$MainContent$ctl00$declaratiebestandView$RetourInformatieGrid$ctl03$DownloadButton','')">CZ_Specificatie_150005697.pdf</a>
field 2
<a id="DownloadButton" href="javascript:__doPostBack('ctl00$ctl00$MainContent$MainContent$ctl00$declaratiebestandView$RetourInformatieGrid$ctl03$DownloadButton','')">CZ_Specificatie_150005697.pdf</a><input name="ctl00$ctl00$MainContent$MainContent$ctl00$declaratiebestandView$RetourInformatieGrid$ctl03$DownloadImage" class="inlineButton" id="DownloadImage" type="image" src="../images/download.png" text="CZ_Specificatie_150005697.pdf">
then it opens the download screen, and then my code continue's (and works :) )
You can loop them by using querySelectorAll to gather all the elements with an id attribute whose values match what you are after. You can distinguish between them by index. This method will allow you to gather them even though the ids are repeating. However, the HTML you have shared downloads the same document so a loop doesn't seem necessary.
Dim nodeList As Object, i As Long
Set nodeList = ie.document.querySelectorAll("[id=DownloadButton]")
For i = 0 to nodeList.Length-1
nodeList.item(i).Click
Next
That loops all of the matching elements and clicks
By index will be specific but if you familiarize yourself with CSS selectors there are a vast number of possibilities for specifying an element.
The id in HTLM must be unique. If it is not unique it is no valid HTML and should be fixed.
HTML4:
http://www.w3.org/TR/html4/struct/global.html
Section 7.5.2:
id = name [CS]
This attribute assigns a name to an element. This name must be unique in a document.
HTML5:
http://www.w3.org/TR/html5/dom.html#the-id-attribute
The id attribute specifies its element's unique identifier (ID). The
value must be unique amongst all the IDs in the element's home subtree
and must contain at least one character. The value must not contain
any space characters.

find_field with Poltergeist/Capybara

I have a problem with Poltergeist. I can’t get the driver to locate a field on a page. What I want to do is to execute some js to make sure that the input field is empty before I start adding new text. I have a field with a label os "Skill list" and id of "user_skill_list". In order to make the step more generic I want to find the field by the label name and then get the id.
And(/^I delete the content of "([^"]*)"$/) do |label|
field_id = page.find_field(label).native.attributes['id'].value
page.execute_script("$('#{field_id}').val('');")
end
Here's the error message:
#javascript
Scenario: Update user by removing # features/godmin/skills.feature:36
Given "Thomas" skills are "rspec, testing" # features/step_definitions/godmin_steps.rb:63
And I click on "Edit" for "Thomas" # features/step_definitions/godmin_steps.rb:43
And I delete the content of "Skill list" # features/step_definitions/godmin_steps.rb:69
Unable to find field "Skill list" (Capybara::ElementNotFound)
./features/step_definitions/godmin_steps.rb:70:in `/^I delete the content of "([^"]*)"$/'
features/godmin/skills.feature:39:in `And I delete the content of "Skill list"'
```
My cucumber set up is pretty basic.
# features/support/env.rb
...
require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist
Capybara.default_max_wait_time = 5
...
Thank you. Please let me know if I should clarify my question.
Assuming your html is something like
<label for="user_skill_list">Skill list</label>
<input id="user_skill_list"/>
Then
page.find_field('Skill list').set('')
should find the field and clear it. If it's not finding the element there are a couple of possibilities.
The element isn't visible on the page
There is CSS being applied that is changing the case of "Skill list"
There are typos in your html so the label isn't actually associated with the field. You can test this by just doing page.find_field('user_skill_list').set('') so the label isn't involved
Note: you can get the id by just doing page.find_field('Skill list')[:id] rather than having to resort to .native.xxxx - although it's not really needed for this use case

Resources