无法使用硒输入凭据

时间:2019-05-21 22:53:05

标签: python selenium

我正在尝试通过以下方式使用 new THREE.MeshBasicMaterial( { map: new THREE.TextureLoader( ).load( 'Images/skybox/PositiveX.png' ), side: THREE.DoubleSide } ), // Right side new THREE.MeshBasicMaterial( { map: new THREE.TextureLoader( ).load( 'Images/skybox/NegativeX.png' ), side: THREE.DoubleSide } ), // Left side new THREE.MeshBasicMaterial( { map: new THREE.TextureLoader( ).load( 'Images/skybox/NegativeY.png' ), side: THREE.DoubleSide } ), // Top side new THREE.MeshBasicMaterial( { map: new THREE.TextureLoader( ).load( 'Images/skybox/PositiveY.png' ), side: THREE.DoubleSide} ), // Bottom side new THREE.MeshBasicMaterial( { map: new THREE.TextureLoader( ).load( 'Images/skybox/PositiveZ.png' ), side: THREE.DoubleSide } ), // Front side new THREE.MeshBasicMaterial( { map: new THREE.TextureLoader( ).load( 'Images/skybox/NegativeZ.png' ), side: THREE.DoubleSide } ) // Back side ]; // Create a MeshFaceMaterial, which allows the cube to have different materials on each face var geometry2 = new THREE.BoxGeometry( 100000, 100000, 100000 ); var cube2 = new THREE.Mesh( geometry2, cubeMaterials ); scene.add( cube2 ); 登录网站:

let el = $('hr').first()
while(el = el.next()){
  if(el.length === 0 || el.prop('tagName') === 'HR') break
  text += el.text() + "\n"
}

但是我收到以下错误

excluded_middle_irrefutable

这是我试图获取的网站的ID标签。 enter image description here

2 个答案:

答案 0 :(得分:2)

here所述,您需要使用javascript人为地单击该元素,因为它是由javascript本身生成的(硒无法“看到”该元素)。相似情况的另一个示例是my answer on this question。像这样调整代码(我也实现了等待,但这可能不是必需的):

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common import action_chains
import time

driver = webdriver.Chrome()
driver.get("https://www.eco-visio.net/v5/")
username_element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//form/div/input[@id='login-username']")))# driver.find_element_by_id("login-username")

driver.execute_script("arguments[0].click();", username_element)
time.sleep(1) # give the click a moment to register
action = action_chains.ActionChains(driver)
action.send_keys("midregcog.admin")
action.perform()

这可以填补我机器上的字段!希望这会有所帮助。

更新

@MarcelWilson指出,您只需要等待页面加载即可(不确定是为什么,因为它是,并且通过几次测试,我不确定为什么仅仅经过明确的等待就不能正常工作。第一个答案过于复杂,您可以使用以下方法实现所需的效果:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

driver = webdriver.Chrome()
driver.get("https://www.eco-visio.net/v5/")
username_element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//form/div/input[@id='login-username']")))# driver.find_element_by_id("login-username")
time.sleep(2) # give a longer wait than the explicit wait in the previous line
username_element.click()
username_element.send_keys("username")
password_element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//form/div/input[@id='login-password'][@type='password']")))# driver.find_element_by_id("login-username")
password_element.click()
password_element.send_keys("password")

我认为这可能是因为在生成页面的javascript中(我也不是javascript专家),其中有诸如if: loaded()之类的行,这使我相信显式WebDriverWait正在元素,但是javascript仍在加载它。因此WebDriverWait确保元素存在,而time.sleep(2)确保在尝试与之交互之前也已加载它。看起来您可以像正常页面一样与它进行交互而没有问题。我甚至还需要为这篇帖子XD学习一些新知识!

答案 1 :(得分:1)

问题是硒正在尝试在元素中完成与DOM的交互。解决此问题的一种方法是将WebDriverWait与Expected_conditions模块结合使用,以“查找”元素并然后与之交互。

尝试这样的事情。

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

driver = webdriver.Chrome()
driver.get("https://www.eco-visio.net/v5/")
wait = WebDriverWait(driver, 10)
ec = EC.visibility_of_element_located((By.ID, "login-username"))
try:
    username = wait.until(ec, f"Could not find {ec.locator}")
    username.send_keys("midregcog.admin")
except Exception as exc:
    raise
finally:
    driver.quit()