[英]How to locate the First name field within shadow-root (open) within the website https://www.virustotal.com using Selenium and Python
[英]Python Selenium - How to locate and add data in textarea which is under #shadow-root (open)
我正在尝试在以下代码的文本区域中找到并输入数据。
但它没有定位元素。
HTML:
<label _ngcontent-c8="" class="form__label form__label--bottom" for="description ">
<span _ngcontent-c8="" class="form__label-inner-wrap"> Product description <span _ngcontent-c8="" aria-label="required">*
</span></span>
</label>
<eds-textarea _ngcontent-c8="" id="productDescTextArea" maxlength="1000" name="description" ng-version="9.1.13">
#shadow-root (open)
<style>....</style>
<style>...</style>
<div class="textarea">
<textarea class="textarea__input u-mb--" placeholder="Please provide a detail description of product." rows="4">
</textarea>
<span id="textarea-character-counter" class="textarea__counter">Characters Available:
<span aria-atomic="false" aria-live="true" aria-relevant="text">1000/1000
</span>
</span>
<!----></div>
</eds-textarea>
</div>
我试过 CSS 定位器:
driver.find_element_by_tag_name("textarea")
driver.find_element_by_css_selector("textarea[placeholder='Please provide a detail description of product.']").send
还有 XPATH:
//textarea[@placeholder='Please provide a detail description of product.']
找不到元素 - 请帮助!
root = driver.find_element_by_id("productDescTextArea")
textarea = driver.execute_script("return arguments[0].shadowRoot.querySelector('textarea[placeholder=\"Please provide a detail description of product.\"]')",root)
您必须调用 shadowRoot 然后使用 querySelector 查找元素
<textarea>
在#shadow-root (open)中。
<eds-textarea _ngcontent-c8="" id="productDescTextArea" maxlength="1000" name="description" ng-version="9.1.13">
#shadow-root (open)
<style>....</style>
<style>...</style>
<div class="textarea">
<textarea class="textarea__input u-mb--" placeholder="Please provide a detail description of product." rows="4">
</textarea>
<span id="textarea-character-counter" class="textarea__counter">Characters Available:
<span aria-atomic="false" aria-live="true" aria-relevant="text">1000/1000
</span>
</span>
<!----></div>
</eds-textarea>
要在<textarea>
字段中发送字符序列,您必须使用shadowRoot.querySelector()
并且可以使用以下定位器策略:
代码块:
element = driver.execute_script("""return document.querySelector('#productDescTextArea').shadowRoot.querySelector('textarea.textarea__input[placeholder^="Please provide a detail description of product"]')""") element.send_keys("Apeksha Mehta")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.