如何从脚本中的目标页面获得“名字”。我尝试了如下所示,但是它引发了以下错误:
"selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: The result of the xpath expression "//div[@class="div_input_place"]/input[@id="txt_name"]/@value" is: [object Attr]. It should be an element."但是,“Name”在其中所指的元素是:
<div class="div_input_place">
<input name="txt_name" type="text" value="CLINTO KUNJACHAN" maxlength="20" id="txt_name" disabled="disabled" tabindex="2" class="aspNetDisabled textboxDefault_de_active_student">
</div>到目前为止我尝试过的脚本:
from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.get("https://www.icaionlineregistration.org/StudentRegistrationForCaNo.aspx")
driver.find_element_by_id('txtRegistNo').send_keys('SRO0394294')
driver.find_element_by_id('btnProceed').click()
time.sleep(5)
name = driver.find_element_by_xpath('//div[@class="div_input_place"]/input[@id="txt_name"]/@value')
print(name.text)
driver.quit()发布于 2017-06-19 17:48:48
Selenium不支持这种语法。XPath表达式应该只返回WebElement,而不是属性值或文本。试着使用下面的代码:
name = driver.find_element_by_xpath('//div[@class="div_input_place"]/input[@id="txt_name"]').get_attribute('value')
print(name)https://stackoverflow.com/questions/44636853
复制相似问题