0

我想在文本区域中输入文本。HTML 代码如下:

<li class="order-unavailable string-type-key string-block clear-fix status-  require_changes expanded working autogrowed activity-opened" data-string_status="require_changes" data-master_unit_count="22" data-string_id="2394473">
<div class="key-area clear-fix">
<div class="key-area-container-one clear-fix">
    <div class="key-area-container-two">
        <div class="col-50 col-left">
            <div class="string-controls">
                <a class="control-expand-toggle selected" href="#"></a>
                <a class="control-activity-toggle " href="#">2</a>
                <input class="control-select-string" type="checkbox">
            </div>
            <div class="master-content">
        </div>
        <div class="col-50 col-right slave-side-container">
    </div>
</div>
</div>
<div class="activity-area clear-fix">
<div class="col-50 col-left">
<div class="col-50 col-right">
    <div class="comment-area-inner">
        <h3>Add comment</h3>
        <div class="comment-container">
        <textarea class="comment-content" name="comment_content"></textarea>
    </div>
    <div class="col-right">
        <div class="clear"></div>
        <strong>Notification settings</strong>
        <p>The people you select will get an email when you post this comment. They'll also be notified by email every time a new comment is added.</p>
        <div class="notification-settings">
        </div>
    </div>
</div>

textarea 组件名称为comment-content

textarea 的 xpath 是:

/html/body/div/section/ol/li[16]/div[2]/div[2]/div/div/textarea

这是我正在使用的代码:

driver.find_element_by_xpath("*//div[@title=\"NOTIFICATION_HOMEPAGE_REDIRECT_CHANGED_SITE\"]
/following-sibling::div[2]/div[2]/div/div/textarea").send_keys("Test comment")

有人可以告诉我如何设置兄弟标签吗?

div[2]/div[2]/div/div/textarea

following-sibling 关键字之前的标签是正确的。

4

1 回答 1

0

选择文本区域并输入一些内容,

driver.find_element_by_xpath(r'//textarea[@class='comment-content']').send_keys('Test Comment')

对于 xpath,您可以使用工具Firepath plugin for Firefox

于 2013-01-05T08:57:12.810 回答