Telefonica / toolium

Wrapper tool of Selenium and Appium libraries to test web and mobile applications in a single project
Apache License 2.0
115 stars 62 forks source link

Parent argument for elements doesn't work properly for some cases #239

Closed DuXspace closed 3 years ago

DuXspace commented 3 years ago

Example of html code: https://61377283aa57c.htmlsave.net/

Case1: In this case first input will be filled, but we selected second element by xpath:

`class Page(PageObject): group_show_block = PageElement(By.XPATH, "//div[@class='modes-block'][2]") topic_input = InputText(By.XPATH, "//input[contains(@class, 'mode-input')]", parent=group_show_block)

Page().topic_input.text = "Hello"`

Case2: Parent argument doesn't work, you can write class that not exist in group_show_block and first input wil be filled,

`class GroupTicketShowModal(Group): group_show_block = PageElement(By.XPATH, "//div[@class='modes-block'][2]") topic_input = InputText(By.XPATH, "//input[contains(@class, 'mode-input')]", parent=group_show_block)

class Page(PageObject): group_ticket_show_modal = GroupTicketShowModal(By.XPATH, "//div[contains(@class, 'modal-body')]")`

Page().group_ticket_show_modal.topic_input.text = "Hello"`

rgonalo commented 3 years ago

Hi @DuXspace , to access using XPATH to a subbelement inside a parent one, a relative path must be used, like .//input[contains(@Class, 'mode-input')] that searches from parent node, instead of an absolute one, like //input[contains(@Class, 'mode-input')] that searches from root node. This is not about Toolium or Selenium, it is an XPATH design, as can be seen in this Selenium discussion: https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/403

DuXspace commented 3 years ago

Hello @rgonalo , aahh, yes you're right, my mistake, sorry for disturbing, i forgot to add dot. As I understand it doesn't work for classes inherited from Group like in Case2, because parent will be that selector "//div[contains(@Class, 'modal-body')]", am i right?

rgonalo commented 3 years ago

Yes, you are right, now an element in a group can not have a custom parent. But I think that could be a useful feature and it would just work with this PR #240.

DuXspace commented 3 years ago

@rgonalo thank you! waiting for review

rgonalo commented 3 years ago

The change is already merged and included in the new release 2.1.1: https://github.com/Telefonica/toolium/releases/tag/2.1.1