Clicking at coordinates without identifying element

前端 未结 14 1922
醉酒成梦
醉酒成梦 2020-11-28 07:49

As part of my Selenium test for a login function, I would like to click a button by identifying its coordinates and instructing Selenium to click at those coordinates. This

14条回答
  •  被撕碎了的回忆
    2020-11-28 07:59

    import pyautogui
    from selenium import webdriver
    
    driver = webdriver.Chrome(chrome_options=options)
    driver.maximize_window() #maximize the browser window
    driver.implicitly_wait(30)
    driver.get(url)
    height=driver.get_window_size()['height']
    
    #get browser navigation panel height
    browser_navigation_panel_height = driver.execute_script('return window.outerHeight - window.innerHeight;')
    
    act_y=y%height
    scroll_Y=y/height
    
    #scroll down page until y_off is visible
    try:
        driver.execute_script("window.scrollTo(0, "+str(scroll_Y*height)+")")
    except Exception as e:
        print "Exception"
    #pyautogui used to generate click by passing x,y coordinates
    pyautogui.FAILSAFE=False
    pyautogui.moveTo(x,act_y+browser_navigation_panel_height)
    pyautogui.click(x,act_y+browser_navigation_panel_height,clicks=1,interval=0.0,button="left")
    

    This is worked for me. Hope, It will work for you guys :)...

提交回复
热议问题