python - Selenium finds element but can't send text to it -


i'm trying send text google flights departure city input box. able find when try , send text send_keys error element not visible. how possible selenium able find input box when send keys not available. did not have error until switched firefox chrome webdriver. code below

import  selenium import webdriver selenium.webdriver.common.keys import keys selenium.webdriver.common.by import selenium.webdriver.support.ui import webdriverwait selenium.webdriver.support import expected_conditions ec  class bot:      def __init__(self):         # self.browser = webdriver.firefox(executable_path='./geckodriver')         self.browser = webdriver.chrome('./chromedriver')         self.departure_city = "cou"         self.destination_city = "hnd"         self.departure_day = "december 1"         self.return_day = "december 10"         self.prices = []         self.run()      def run(self):         try:             self.setflight()             self.setdates()             self.findprices()             self.sendtext()             time.sleep(10)             self.browser.quit()           except exception ex:             print(ex)             self.browser.quit()      def setflight(self):         self.browser.get('https://www.google.com/flights/');         departure_take_off_boxes = self.browser.execute_script(             "return document.queryselectorall('.eigtdnc-kb-f.eigtdnc-kb-b')")         print(departure_take_off_boxes[0].get_attribute('outerhtml'))         print(departure_take_off_boxes[1].get_attribute('outerhtml'))         self.browser.implicitly_wait(20)         departure_take_off_boxes[0].send_keys(self.departure_city)         departure_take_off_boxes[0].send_keys(keys.return)         time.sleep(1)         # departure_take_off_boxes[1].send_keys(self.destination_city)         # departure_take_off_boxes 

analysis:

selenium can find element page, means element has html code in page source, not equal element visible on page. difference between ispresent() , isdisplay().

for selenium how determine element visible, knwo rules below:
1. element size not 0
2. element 'display' css value not 'none'

i feel strange why can run pass firefox driver on chrome driver, guess webdirver specification on w3c had defined that, maybe firefox , chrome implement difference in webdriver.

back reason why input box not visible, html code round input box, noticed there div layer cover on top on input box, , input box size set 1x1 in css style.

enter image description here

i tried hidden covered div layer , uncheck width , height setting in css, after can see , can input value.

i'm not sure t, selenium used following rule determine element visible:

if there cover element, element not visible. 

but user experience, user can't see element, , selenium api try best close user experience.

solution:

even make element div layer, size small, input value, sitll can't see text input.

and ui design issue, need communicate dev team.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -