Python/Selenium:如何在输入按钮中打印文本('str' 对象不可调用 + 文本不在 html 中)
Python/Selenium: How to print text in an input button ('str' object is not callable + text not in html)
我正在尝试使用 selenium 编写一个临时邮件脚本,我想获得下图中突出显示的文本。
邮件没有出现在 html:
<input id="mail" type="text" onclick="select(this);" data-original-title="Your Temporary Email Address" data-placement="bottom" data-value="Loading" class="emailbox-input opentip" readonly="">
我一直在尝试这个脚本:
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
driver = webdriver.Chrome(executable_path="C:\Program Files (x86)\chromedriver.exe")
driver.get("https://temp-mail.org/en/") # loading page
wait = WebDriverWait(driver, 20) # defining webdriver wait
print(wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'input-box-col'))).text())
但出现此错误:
C:\Users\fkahd\PycharmProjects\cryptodata\sanbox3.py:7: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Chrome(executable_path="C:\Program Files (x86)\chromedriver.exe")
Traceback (most recent call last):
File "C:\Users\fkahd\PycharmProjects\cryptodata\sanbox3.py", line 11, in <module>
print(wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'input-box-col'))).text())
TypeError: 'str' object is not callable
我知道我可以通过单击站点上的复制按钮然后执行打印剪贴板的功能来绕过它,但我认为我可以将此信息用于未来的项目,了解如何获取此文本.
没有 text()
方法,但 text 是 属性。
实际上,您的代码行将是:
wait = WebDriverWait(driver, 20) # defining webdriver wait
print(wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'input-box-col'))).text)
我正在尝试使用 selenium 编写一个临时邮件脚本,我想获得下图中突出显示的文本。
邮件没有出现在 html:
<input id="mail" type="text" onclick="select(this);" data-original-title="Your Temporary Email Address" data-placement="bottom" data-value="Loading" class="emailbox-input opentip" readonly="">
我一直在尝试这个脚本:
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
driver = webdriver.Chrome(executable_path="C:\Program Files (x86)\chromedriver.exe")
driver.get("https://temp-mail.org/en/") # loading page
wait = WebDriverWait(driver, 20) # defining webdriver wait
print(wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'input-box-col'))).text())
但出现此错误:
C:\Users\fkahd\PycharmProjects\cryptodata\sanbox3.py:7: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Chrome(executable_path="C:\Program Files (x86)\chromedriver.exe")
Traceback (most recent call last):
File "C:\Users\fkahd\PycharmProjects\cryptodata\sanbox3.py", line 11, in <module>
print(wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'input-box-col'))).text())
TypeError: 'str' object is not callable
我知道我可以通过单击站点上的复制按钮然后执行打印剪贴板的功能来绕过它,但我认为我可以将此信息用于未来的项目,了解如何获取此文本.
没有 text()
方法,但 text 是
实际上,您的代码行将是:
wait = WebDriverWait(driver, 20) # defining webdriver wait
print(wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'input-box-col'))).text)