vendredi 29 septembre 2017

How to click on an element based on its coordinates with selenium webdriver

So, the web app we're developing has a TV/PC mode, and i'm testing the ability to transit between these two modes. `

 def pc_to_tv(self):
        pc_to_tv = self.driver.find_element_by_xpath(
            'html/body/div[1]/div/topbar/header/div[2]/div[2]/div[1]/button[1]')
        pc_to_tv.click()

 def tv_to_pc(self):
      tv_to_pc = self.driver.find_element_by_xpath(
            'html/body/div[1]/div/topbar/header/div[2]/div[2]/div[1]/button[2]')
      tv_to_pc.click()`

The problem is, when i switch from pc to tv, the screen "zooms in", making the button appear in the same place it would be without the zoom. so, i can't click on the button with my 'tv_to_pc' method, 'cause instead on clicking on the actual button, it clicks where the button should be.

So, the solution i found was clicking on the button with coordinates, that way i'll actually click on the place i want, instead of clicking on an unclickable place like i was doing.

The thing is, i don't know how to do this, and need help on this matter.

Aucun commentaire:

Enregistrer un commentaire