Python Forum
Field with dynamic id not found at playback - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Field with dynamic id not found at playback (/thread-24576.html)



Field with dynamic id not found at playback - pythonscripting - Feb-20-2020

I record a short sequence with Selenium IDE on a SAP gui:

1   self.driver.find_element(By.ID, "M0:U:::5:53").click()
2   self.driver.switch_to.default_content()
3   self.driver.switch_to.frame(2)
4   self.driver.find_element(By.ID, "M1:U:1::0:1-title").click()
5   self.driver.find_element(By.ID, "tbl102[1,2]_c").click()
6   self.driver.find_element(By.ID, "tbl102[1,2]_c").send_keys("123")
7   self.driver.find_element(By.ID, "tbl102[1,3]_c").click()
8   self.driver.find_element(By.ID, "tbl102[1,3]_c").send_keys("456")
at playback time everything works fine until row 5
rows 2-3 change to a new frame
row 4 in the new frame clicks just fine a title
rows 5-8 don't find the field because the id tbl102[1, 2] is dynamic where the xxx change every time (tblxxx[1, 2])
ok, so I implement id with wildcards. But nothing seems to work:

loaded = len(browser.find_elements_by_xpath('//*[@id]'))
loaded = len(browser.find_elements_by_xpath('//*[contains(@id, "tbl") AND contains(@id, "_c")]')) (This one is error syntax)

browser.find_elements_by_id('*[1,3]_c')
browser.find_elements_by_id('*[*')

browser.find_elements_by_xpath('//*[contains(@id, "[1,3]_c")]').click()
browser.find_elements_by_xpath('//*[contains(@id, "[1,3]_c")]').send_keys("242")

browser.find_element(By.xpath("//*[ends-with(@id, ‘[1,3]_c’)]").click()
browser.find_element(By.xpath("//*[ends-with(@id, ‘[1,3]_c’)]").send_keys("242")

browser.find_elements(By.Id("tbl*"))

browser.find_elements(By.xpath("//[starts-with(@id, ‘tbl’)]");
browser.find_elements(By.xpath("//[contains(@id, ‘tbl’)]");
browser.find_elements(By.xpath("//*[ends-with(@id, ‘_c’)]");
None of the above gives hit. So I print out all elements in the frame with some kind of id:

el = browser.find_elements_by_xpath('//*[contains(@id, "t")]')
for i in el:
    if len(i.text) > 0:
        print(">" + i.text + "<")
And to my surprise there are no elements containing "tbl" AT ALL!!

The code above I execute right after row 4 in my first code at the top which works fine and proves that I am in the right frame.

Anyone has an idea of what is happening?

However after rows 5-8 have been executed and py/selenium has not been able to write to the field I do an inspect (FF).
The field has id=tbl327[1,3]_c which should be able to be detected by one of the wildcard id above. But NOT.

In row 4 py/selenium clicks on 'Select Ranges' folder that is in the same frame as the fields in rows 5-8
In my book that proves that I am in the right frame. Or not? what do you guys think?

Will appreciate all ideas leading to solve the issue.

[Image: 75GLdvrz]