【发布时间】:2021-08-19 14:04:34
【问题描述】:
我有一个包含以下元素的页面(我无法共享 URL,因为该页面是私有的):
<input readonly="" type="text" class="form-control" id="submissionKey" value="{{ token }}" style="font-size:1.2em;color:black; width: 400px">
我正在尝试通过以下方法获得:
element = driver.find_element_by_id("submissionKey")
但这只会报错:
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: [id="submissionKey"]
我也尝试像这样实现一些等待:
wait = WebDriverWait(driver, 10)
element = wait.until(EC.element_to_be_clickable((By.ID, 'submissionKey')))
然后报错
selenium.common.exceptions.TimeoutException: Message:
我在这里错过了什么?
其他信息
- 看起来不像是时区问题
- 不涉及 iframe。
完整的页面正文:
<body style="margin:20px">
<p>Go to <b>Jupyter Notebook</b> and complete the exercise.</p>
<form class="form-inline">
<div class="input-group">
<div class="input-group-addon" style="width:40px;font-size:1.2em"><i class="fa fa-key" aria-hidden="true"></i></div>
<input readonly="" type="text" class="form-control" id="submissionKey" value="{{ token }}" style="font-size:1.2em;color:black; width: 400px">
</div>
</form>
<p style="margin-left:55px"><small>Use this key to fetch the simulation results in the notebook in order to complete the exercise.</small></p>
<script>
console.log('window', window.location.search);
var queryString = window.location.search; // Returns:'?q=123'
let params = new URLSearchParams(queryString);
let auth = params.get("auth");
var input = document.getElementById('submissionKey');
input.value = auth;
</script>
</body>
【问题讨论】:
-
我猜它的时区问题,再次检查并判断它是否不工作,伙计
-
你检查过 iframe 吗?可以分享一下网址吗?
-
无时区问题,不涉及 iframe
-
你能分享页面网址吗?我怀疑会有多个元素。
-
不,我不能。它不公开