我正在使用Python使用selenium。我正在尝试访问网页中的列表框,但是我收到以下错误。
# define folders
folderWD <- "/users/myName/myXproject/"
folderInput <- paste0(folderWD, "data/")
folderOutput <- paste0(folderWD, "output/")
# input output files
fileInput <- paste0(folderInput, "filename.txt")
fileOutput <- paste0(folderOutput, tools::file_path_sans_ext(basename(fileInput)), ".csv")
# test
fileInput
# [1] "/users/myName/myXproject/data/filename.txt"
fileOutput
# [1] "/users/myName/myXproject/output/filename.csv"
#then codez
myInputData <- read.csv(fileInput, header = FALSE)
...
Newfile <- # do some stuff with myInputData
...
write.csv(Newfile, fileOutput)
以下是我尝试访问的列表框的HTML标记:
selenium.common.exceptions.NoSuchElementException:
Message: Unable to locate element: {"method":"name","selector":"s_2_1_0_0"}
我已经使用了两个名字和&amp; id如下所示,但仍然高于错误。
<select id="s_2_1_0_0" name="s_2_1_0_0" style="width:175px"
onchange="chkQuickStartType(this)" id="s_2_1_0_0" tabindex="1997">
答案 0 :(得分:0)
selenium.common.exceptions.NoSuchElementException: 消息:无法找到元素:{“method”:“name”,“selector”:“s_2_1_0_0”}
我认为欲望元素的function handleDisable(checkbox)
{
var text = document.getElementsByName("locationId")[0]
var button = document.getElementsByName("lookupLocation")[0]
if(checkbox.checked == true) {
text.disabled = false;
button.disabled = false;
}
else {
text.disabled = true;
button.disabled = true;
}
}
属性值不固定,这就是你无法找到的原因。
您应该尝试使用不同的定位器来定位相同的元素。我建议您尝试使用name/id
,如下所示: -
find_element_by_css_selector()