python中的selenium sendkeys不起作用

时间:2018-02-22 09:47:20

标签: python-2.7 xpath selenium-webdriver web-scraping sendkeys

我有这段代码:

from selenium import webdriver
#open Firefox
driver=webdriver.Firefox()
#open arbitrary ur
url="https://www.scopus.com/search/form.uri?display=basic"
driver.get(url)
#click on input  element for writing special word
search=driver.find_element_by_xpath("""//*[@id="txtBoxSearch"]/label""")
search.click()
driver.implicitly_wait(5)
#write your special word
search.send_keys("internet of things")
driver.implicitly_wait(5)
search.submit()

错误堆栈跟踪:

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: Element <label class="inputTextLabel activeInputLabel"> is not reachable by keyboard

打开网址并识别x路径,但send_keys不起作用。我该怎么办?

1 个答案:

答案 0 :(得分:0)

library(xgboost) #sample data data(agaricus.train, package='xgboost') data(agaricus.test, package='xgboost') dtrain <- xgb.DMatrix(agaricus.train$data, label = agaricus.train$label) dtest <- xgb.DMatrix(agaricus.test$data, label = agaricus.test$label) watchlist <- list(train=dtrain, test=dtest) #training XGBoost model param <- list(max_depth = 2, eta = 1, nthread = 2, objective = "binary:logistic", eval_metric = "auc", eval_metric="error") fit <- xgb.train(param, data=dtrain, nrounds=10, watchlist=watchlist, verbose = 2) 节点只是输入字段的“名称”,您无法将密钥发送到此元素。您需要处理文本label节点。

假设HTML看起来像

input

你可以尝试

<div id='txtBoxSearch'>
    <label>Search</label>
    <input type='text'>
</div>