无法在第二次迭代中获取元素

时间:2019-04-12 11:27:20

标签: python selenium-webdriver

要求:需要自动化其中需要添加多个设备的服务器的WebUi。

问题:在添加设备时,每次将在需要添加设备详细信息的地方打开一个弹出窗口。可以添加第一个设备,但是对于第二个设备,我遇到了错误:

“无线错误:消息:元素“ input class =” default-input“ type =” search“”无法滚动到视图中“

已经检查了元素,并且每个设备添加弹出窗口的元素都保持不变。

我正在使用css选择器,代码片段:

self.e_css_device_name =“ #addDeviceTab ._deviceNameRow ._deviceName输入”

        try:
            #click to Add -----------------------------------------------------------------
            add_device = self.driver.find_element_by_css_selector(self.e_css_add_device)
            try:
                ActionChains(self.driver).move_to_element(add_device).perform()
            except Exception as e:
                self.driver.execute_script("arguments[0].scrollIntoView(false);", add_device)
            add_device.click()
            time.sleep(10)
            #add details---------------------------------------------------------------
            WebDriverWait(self.driver, 10, 0.1).until(
                EC.presence_of_element_located((By.CSS_SELECTOR, self.e_css_device_name)))
            device_name = self.driver.find_element_by_css_selector(self.e_css_device_name)
            try:
                ActionChains(self.driver).move_to_element(device_name).perform()
            except Exception:
                self.driver.execute_script("arguments[0].scrollIntoView(false);", device_name)
            device_name.clear()
            device_name.send_keys(str(self.device_name))
            time.sleep(2)

也尝试过:

            WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable(
                (By.CSS_SELECTOR, self.e_css_device_name)))
            device_name.click()
            device_name.clear()
            device_name.send_keys(str(self.device_name))
            time.sleep(2)

0 个答案:

没有答案