Селен - как нажать на область пробела в текстовом поле - PullRequest
0 голосов
/ 27 ноября 2018

Я пытаюсь щелкнуть область пробела в текстовом поле, а не в тексте элемента.Это возможно в селене или есть какой-то другой хитрый подход?

enter image description here

Красная стрелка расположена там, где я хочу нажать

HTML:

<td class="ms-srm-Field-Data-Print" data-height="24" id="stan_servicecategoryid_d">
    <div id="stan_servicecategoryid" data-attributename="stan_servicecategoryid" data-formid="bfef905d-acd0-4ee9-a900-2034792789c1" data-fdeid="PrimaryEntity" data-layout="0" tabindex="1070" isinline="true" lookupstyle="single" lookupdialogmultipleselect="0" isinlinenewenabled="1" showasbreadcrumbcontrol="0" showglobalquickcreate="0" openfullform="1" addlookupimagebutton="" role="application" entitylogicalname="stan_servicecategory" entitydisplayname="Service Category" entitytypecode="10041" allowfilteroff="0" disablequickfind="0" disableviewpicker="1" disablemru="1" isdeduplookup="0" availableviewids="{EA878523-32E1-49BB-B0C5-FF97230B5AF2}" resolveemailaddress="0" allowunresolvedpartiesonemailsend="0" defaultviewid="{152B96D2-3BF4-469E-8BB4-52C639E51E50}" class="ms-srm-Inline-Chrome lookup nvarchar" aria-label="Service Category Unique identifier for Service Category associated with Service Request.  test Select the Enter key to edit the lookup field, and the Control and Enter keys to open the link">
        <div class="ms-srm-Inline-Value ms-srm-Inline-Lookup" style="display: block;">
            <label data-for-id="stan_servicecategoryid_label" id="Service Category_label">
                <div class="ms-srm-div-NotVisible">Service Category</div>
            </label>
            <span>
                <span contenteditable="false" class="ms-srm-Lookup-Item" id="stan_servicecategoryid_lookupValue" title="test" tabindex="0">test</span>
                <div class="ms-srm-Inline-EditIcon keyboardFocusClass" id="stan_servicecategoryid_lookupSearchIconDiv" style="display: none;">
                    <img src="/_imgs/imagestrips/transparent_spacer.gif" id="stan_servicecategoryid_lookupSearchIcon" class="ms-srm-ImageStrip-search_normal ms-srm-InlineLookupEdit ms-srm-EditLookup-Image" alt="">
                </div>
            </span>
        </div>
        <div class="ms-srm-Inline-Edit ms-srm-Inline-Lookup" style="display: none;" lookuptypes="10041">
            <table id="stan_servicecategoryid_lookupTable" cellpadding="0" cellspacing="0" lookupid="stan_servicecategoryid" class="ms-srm-Lookup" aria-labelledby="stan_servicecategoryid_c stan_servicecategoryid_w" controlmode="normal" style="width: 100%;table-layout: fixed;">
                <tbody>
                    <tr>
                        <td valign="top">
                            <div id="stan_servicecategoryid_lookupDiv" ime-mode="auto" class="ms-srm-Lookup ms-srm-InlineLookupEdit" tabindex="0" aria-labelledby="stan_servicecategoryid_lookupedit" title="Service Category Unique identifier for Service Category associated with Service Request.  test" style="display: block; background-color: rgb(171, 192, 231); width: 100%;">
                                <ul class="ms-srm-InlineLookupEdit">
                                    <li style="display: inline; white-space: nowrap;">
                                        <span class="ms-srm-Lookup-Item" contenteditable="false" isinlinelookup="true">
                                            <span class="ms-srm-LookupItem-Name" id="stan_servicecategoryid_lookupEditSpan" title="test" otype="10041">test</span>
                                        </span>
                                    </li>
                                </ul>
                            </div>
                            <label id="stan_servicecategoryid_lookupedit" class="ms-srm-Hidden-NoBehavior" for="stan_servicecategoryid_ledit">Enter a search term, then select the Enter key to search</label>
                            <input class="ms-srm-InlineInput ms-srm-InlineLookupEdit" ime-mode="auto" aria-labelledby="stan_servicecategoryid_lookupedit stan_servicecategoryid_w" type="text" id="stan_servicecategoryid_ledit" maxlength="1000" style="display: none;">
                        </td>
                        <td class="ms-srm-InlineLookupEdit-Box"></td>
                        <td class="Lookup_RenderButton_td" id="stan_servicecategoryid_lookupSearch" style="vertical-align:top;width:22px;">
                            <img src="/_imgs/search_normal.gif" id="stan_servicecategoryid_i" alt="Select a value." class="ms-srm-InlineLookupEdit" title="Select a value.">
                            <a href="#" id="stan_servicecategoryid_a" tabindex="-1" title="Select a value."></a>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <span class="ms-srm-Inline-LockIcon" id="stan_servicecategoryid_lock" style="display: none;">
            <img src="/_imgs/imagestrips/transparent_spacer.gif" class="ms-srm-ImageStrip-inlineedit_locked" alt="Locked control">
        </span>
        <span class="ms-srm-Inline-fieldChangeIndicatorIcon" id="stan_servicecategoryid_fieldChangeIndicatorImage" style="visibility: hidden;">
            <img src="/_imgs/imagestrips/transparent_spacer.gif" class="ms-srm-ImageStrip-field_change_indicator" alt="">
        </span>
        <span id="stan_servicecategoryid_warnSpan" class="ms-srm-Inline-WarningIcon" title="" style="display: none;" role="alert" aria-live="assertive" aria-atomic="true">
            <img src="/_imgs/imagestrips/transparent_spacer.gif" class="ms-srm-ImageStrip-inlineedit_warning" alt="Error" id="stan_servicecategoryid_warn">
            <div id="stan_servicecategoryid_w" class="ms-srm-Hidden-NoBehavior"></div>
        </span>
    </div>
    <div style="display:none;"></div>
</td>

Селен:

driver.FindElement(By.Id("stan_servicecategoryid_lookupValue").Click();

new Actions(driver).MoveToElement(driver.FindElement(by)).SendKeys(Keys.Clear).Perform(); // This will clear the value of the text box

1 Ответ

0 голосов
/ 28 ноября 2018

Использовать ACTIONS (или ActionChains в Python)

Если вы имитируете moveToElement (element) и click (), он щелкает точно в центре элемента.Если текст длинный и выше все еще щелкает по тексту, используйте moveToElement (со смещением), присваивая ему смещение по оси X при необходимости.

Java:

Actions action = new Actions(driver);
action.moveToElement(element).click().perform();

или

action.moveToElement(element, x-offset, 0).click().perform();

Python:

from selenium.webdriver.common.action_chains import ActionChains as AC

AC(driver).move_to_element(element).click().perform()

или

AC(driver).move_to_element_with_offset(element, x-offset, 0).click().perform()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...