我想在我的控制台中得到发送者的文本。这是当前的代码,
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
opt = Options()
opt.add_experimental_option("debuggerAddress","localhost:1234")#code for the browser
driver = webdriver.Chrome(executable_path="C:\Program Files (x86)\chromedriver.exe",chrome_options=opt)#uses the chromedriver
#driver.get("https://www.instagram.com/")#opens website
driver.find_element(By.CLASS_NAME,"_ab8w _ab94 _ab97 _ab9f _ab9k _ab9p _ab9_ _aba8 _abcm").send_keys(Keys.RETURN)尽管我检查了页面并找到了文本消息的类名(文本消息的类名为"_ab8w _ab94 _ab97 _ab9f _ab9k _ab9p ab9 _aba8 _abcm"),但我仍然收到一个元素找不到的错误。这些短信也没有我可以使用的ID。
我想要控制台中的文本:链接到文本图片
我尝试过延迟程序,所以它会等待页面加载,但这是行不通的。
发布于 2022-11-05 17:29:24
CLASS_NAME的搜索需要一个类名来查找元素。但是在这里你给它起了很多的名字。" Class“属性中的类名由空格分隔。因此,"_ab8w _ab94 _ab97 _ab9f _ab9k _ab9p ab9 _aba8 _abcm“不是类名,而是由空格分隔的类列表。
例如,如果设置了By.CLASS_NAME,driver.find_element(By.CLASS_NAME,"_ab8w").send_keys(Keys.RETURN)就会找到一些东西。但我怀疑这是那个页面唯一的类名。
您可以使用这个定位器(By.XPATH,"//*[@class='_ab8w _ab94 _ab97 _ab9f _ab9k _ab9p ab9 _aba8 _abcm']")使用所有的类列表找到这个元素。整条线将如下所示:
driver.find_element(By.XPATH,"//*[@class='_ab8w _ab94 _ab97 _ab9f _ab9k _ab9p ab9 _aba8 _abcm']").send_keys(Keys.RETURN)https://stackoverflow.com/questions/74322810
复制相似问题