#python #selenium
#python #селен
Вопрос:
Я не знаю элемент, используемый для ввода поля.
Я пытался написать так:
driver.find_element_by_xpath("//div[@class='query-input-box well']")
driver.find_element_by_xpath("//div[contains(@class,'query-input-box well')]")
driver.find_element_by_xpath("//div[@class='query-input-box well']")
HTML:
<div class="query-input-box well"><div class="ReactCodeMirror"><textarea autocomplete="off" style="display: none;"></textarea><div class="CodeMirror cm-s-default CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 4px; left: 21px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" style="position: absolute; padding: 0px; width: 1000px; height: 1em; outline: none;" tabindex="0"></textarea></div><div class="CodeMirror-vscrollbar" cm-not-content="true"><div style="min-width: 1px; height: 0px;"></div></div><div class="CodeMirror-hscrollbar" cm-not-content="true"><div style="height: 100%; min-height: 1px; width: 0px;"></div></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 17px; margin-bottom: 0px; border-right-width: 30px; min-height: 28px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-cursors" style=""><div class="CodeMirror-cursor" style="left: 4px; top: 0px; height: 20px;">amp;nbsp;</div></div><div class="CodeMirror-code"><pre class=" CodeMirror-line "><span style="padding-right: 0.1px;"><span cm-text=""></span></span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; border-bottom: 0px solid transparent; top: 28px;"></div><div class="CodeMirror-gutters" style="height: 58px; left: 0.0078125px;"><div class="CodeMirror-gutter CodeMirror-lint-markers"></div></div></div></div></div></div>
Больше HTML-кода
<div class="panel panel-primary asin-discovery-form"><div class="panel-heading" aria-describedby="panelHeadTooltip"><!-- react-text: 4 -->Find ASINs<!-- /react-text --><span class="panel-head-icon"><span class="glyphicon glyphicon-collapse-up glyphicon--white glyphicon--large"></span></span></div><div class="panel-collapse collapse in"><div class="panel-body"><div class="container"><div class="show-grid row"><div class="col-xs-6"><div class="form-group"><label>Enter ASINs or query or upload content from a text file</label><a href="/searchableFields" target="_blank" class="indexed-fields-link">Searchable Fields</a><div class="query-input-box well"><div class="ReactCodeMirror"><textarea autocomplete="off" style="display: none;"></textarea><div class="CodeMirror cm-s-default CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 4px; left: 21px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" style="position: absolute; padding: 0px; width: 1000px; height: 1em; outline: none;" tabindex="0"></textarea></div><div class="CodeMirror-vscrollbar" cm-not-content="true"><div style="min-width: 1px; height: 0px;"></div></div><div class="CodeMirror-hscrollbar" cm-not-content="true"><div style="height: 100%; min-height: 1px; width: 0px;"></div></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 17px; margin-bottom: 0px; border-right-width: 30px; min-height: 28px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><span><span></span>x</span></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-cursors"><div class="CodeMirror-cursor" style="left: 4px; top: 0px; height: 20px;">amp;nbsp;</div></div><div class="CodeMirror-code"><pre class=" CodeMirror-line "><span style="padding-right: 0.1px;"><span cm-text=""></span></span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; border-bottom: 0px solid transparent; top: 28px;"></div><div class="CodeMirror-gutters" style="height: 58px; left: 0.0078125px;"><div class="CodeMirror-gutter CodeMirror-lint-markers"></div></div></div></div></div></div><input type="file" class="file-loading"></div></div><div class="col-xs-6"><div class="row"><div class="col-xs-7"><div class="row"><div class="col-xs-7"><b>Images:</b></div><div class="col-xs-5"><div class="form-group"><div class="bootstrap-switch wrapper bootstrap-switch-on bootstrap-switch-small bootstrap-switch-animate" tabindex="0" style="width: 88px;"><div class="bootstrap-switch-container" style="width: 132px; margin-left: 0px;"><span class="bootstrap-switch-handle-on bootstrap-switch-primary" style="width: 44px;">ON</span><span class="bootstrap-switch-label" style="width: 44px;"> </span><span class="bootstrap-switch-handle-on bootstrap-switch-default" style="width: 44px;">OFF</span></div></div></div></div></div><div class="row"><div class="col-xs-7"><b>Suggest Browse Nodes:</b></div><div class="col-xs-5"><div class="form-group"><div class="suggest-browse-node-form" aria-describedby="suggest-browse-node-popover"><div class="bootstrap-switch wrapper bootstrap-switch-off bootstrap-switch-small bootstrap-switch-animate" tabindex="0" style="width: 88px;"><div class="bootstrap-switch-container" style="width: 132px; margin-left: -44px;"><span class="bootstrap-switch-handle-on bootstrap-switch-primary" style="width: 44px;">ON</span><span class="bootstrap-switch-label" style="width: 44px;"> </span><span class="bootstrap-switch-handle-on bootstrap-switch-default" style="width: 44px;">OFF</span></div></div></div></div></div></div><div class="row"><div class="col-xs-12"><div class="form-group"><label for="pageSize" class="control-label">Page Size:</label><select id="pageSize" class="form-control"><option value="25">25</option><option value="50">50</option><option value="250">250</option><option value="500">500</option><option value="1000">1000</option><option value="2000">2000</option></select></div></div></div></div><div class="col-xs-5"><div></div></div></div><div class="row"><div class="col-xs-12"><div class="form-group"><label for="browseNodeFilter" class="control-label">Browse Node Filter:</label><select id="browseNodeFilter" class="form-control"><option value="">none</option><option value="category-node-live-on-website">category-node-live-on-website</option><option value="category-node-merchant-facing">category-node-merchant-facing</option><option value="category-node-assignment-eligible">category-node-assignment-eligible</option><option value="autoclassification-decoder-suggestions">autoclassification-decoder-suggestions</option><option value="browse-util-unhidden-category-branch">browse-util-unhidden-category-branch</option><option value="detail-page-ladders-truncate">detail-page-ladders-truncate</option></select></div></div></div><div class="row"><div class="col-xs-12"><div class="section"><label>Catalog Attributes:</label><div class="attribute-search-options"><!-- react-text: 73 -->Matching pattern<!-- /react-text --><div class="buttons btn-group btn-group-xs"><button type="button" class="btn btn-default active">Starts with</button><button type="button" class="btn btn-default">Contains</button></div></div><div class="Select Select--multi is-searchable has-value"><div class="Select-control"><span class="Select-multi-value-wrapper" id="react-select-2--value"><div class="Select-value"><span class="Select-value-icon" aria-hidden="true">×</span><span class="Select-value-label" role="option" aria-selected="true" id="react-select-2--value-0"><!-- react-text: 227 -->title<!-- /react-text --><span class="Select-aria-only">amp;nbsp;</span></span></div><div class="Select-value"><span class="Select-value-icon" aria-hidden="true">×</span><span class="Select-value-label" role="option" aria-selected="true" id="react-select-2--value-1"><!-- react-text: 232 -->attribute<!-- /react-text --><span class="Select-aria-only">amp;nbsp;</span></span></div><div class="Select-value"><span class="Select-value-icon" aria-hidden="true">×</span><span class="Select-value-label" role="option" aria-selected="true" id="react-select-2--value-2"><!-- react-text: 237 -->recommended_browse_nodes<!-- /react-text --><span class="Select-aria-only">amp;nbsp;</span></span></div><div class="Select-value"><span class="Select-value-icon" aria-hidden="true">×</span><span class="Select-value-label" role="option" aria-selected="true" id="react-select-2--value-3"><!-- react-text: 242 -->brand_name<!-- /react-text --><span class="Select-aria-only">amp;nbsp;</span></span></div><div class="Select-input" style="display: inline-block;"><input role="combobox" aria-expanded="false" aria-owns="" aria-haspopup="false" aria-activedescendant="react-select-2--value" value="" style="box-sizing: content-box; width: 2px;"><div style="position: absolute; top: 0px; left: 0px; visibility: hidden; height: 0px; overflow: scroll; white-space: pre; font-size: 14px; font-family: amp;quot;Helvetica Neueamp;quot;, Helvetica, Arial, sans-serif; font-weight: 400; font-style: normal; letter-spacing: normal;"></div></div></span><span class="Select-clear-zone" title="Clear all" aria-label="Clear all"><span class="Select-clear">×</span></span><span class="Select-arrow-zone"><span class="Select-arrow"></span></span></div></div></div></div></div><div class="row"><div class="col-xs-4 col-xs-push-4"><button type="button" class="submit-button btn btn-default">Export...</button><div class="export-collapse collapse"><div class="well"><!-- react-text: 93 -->Select export size:<!-- /react-text --><div class="Select Select--single is-searchable has-value"><div class="Select-control"><span class="Select-multi-value-wrapper" id="react-select-3--value"><div class="Select-value"><span class="Select-value-label" role="option" aria-selected="true" id="react-select-3--value-item">10K</span></div><div class="Select-input" style="display: inline-block;"><input role="combobox" aria-expanded="false" aria-owns="" aria-haspopup="false" aria-activedescendant="react-select-3--value" value="" style="box-sizing: content-box; width: 2px;"><div style="position: absolute; top: 0px; left: 0px; visibility: hidden; height: 0px; overflow: scroll; white-space: pre; font-size: 14px; font-family: amp;quot;Helvetica Neueamp;quot;, Helvetica, Arial, sans-serif; font-weight: 400; font-style: normal; letter-spacing: normal;"></div></div></span><span class="Select-arrow-zone"><span class="Select-arrow"></span></span></div></div><button type="button" class="btn btn-default">Confirm</button></div></div></div><div class="col-xs-4 col-xs-offset-4"><button type="button" class="submit-button btn btn-primary">Execute Query</button></div></div></div></div></div></div></div></div>
изображение:
https://imgur.com/a/KoLbCKZ
Комментарии:
1. Кажется, текстовая область скрыта, можете ли вы поделиться URL-адресом сайта, если это возможно, или моментальным снимком с html и вашим элементом на странице
2. Внутренний веб-сайт, я могу поделиться большим количеством HTML-кода
3. @hakukou Вы можете проверить, включен ли он
iframe
?4. @Fenio Я не знаю, как проверить
5. Поскольку упомянутая @NarendraR текстовая область скрыта , каков ваш следующий шаг после определения местоположения элемента? Вы можете сделать это вручную ?
Ответ №1:
Попробуйте использовать javascript для поиска элемента
((JavascriptExecutor)driver).executeScript("document.getElementsByClassName('query-input-box well')[0]");
и выполните действия с javascript, которые вы хотите.
потому что, если элемент находится во фрейме или скрыт, selenium не может найти этот элемент