Python Selenium无法发送键(找不到输入)

问题描述 投票:0回答:2

我是python selenium的新手,今天我被困在一个元素上,我不知道为什么,但是我找不到该元素和sendkeys。谁能为我解释为什么我无法通过id / xpath / css选择器找到它?以及我们如何找到它和sendkeys? 这里是元素的图像The Element,网站是:https://www.messenger.com/ PS :(我已经尝试过java_execute_script,但它不起作用,我仍然不知道如何好好用)

python-3.x selenium element sendkeys
2个回答
0
投票

我正在使用python编写硒程序。我认为您可以按F12键并检查html代码。

我帮助您检查班级名称。我检查了班级名称是_1mf,但不确定您的班级名称是什么。您可以检查一下。

enter image description here

然后,您需要使用以下代码来完成它。

k=driver.find_element_by_class_name("_1mf")
k.send_keys('testing')
from selenium.webdriver.common.keys import Keys
k.send_keys(Keys.RETURN) 

'testing'是我的输入元素。您可以更改它。“ k”是我的变量。您可以更改它。

我不确定这是正确的答案。

您也可以参考以下视频:

https://www.largitdata.com/course/105/
https://www.largitdata.com/course/104/

0
投票

请找到以下解决方案

inputBox = wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@class='_kmc _7kpg navigationFocus']")))
actionChains = ActionChains(driver)
actionChains.move_to_element(inputBox).send_keys("Username").perform()

注意:请在下方导入您的解决方案

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

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.