нажмите кнопку отправки в всплывающем окне div по селену python - PullRequest
0 голосов
/ 30 апреля 2020

это мой код

driver.find_element_by_xpath('//*[@id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.btn_ok2"]').click()

и это код цели

<div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form" class="Form" tabindex="-1" status="focused" style="left: 0px; top: 0px; width: 424px; height: 342px;"><div class="nexacontainer" id="nexacontainer" style="width: 424px; height: 342px;"><div class="nexainnercontainer" id="nexacontainer" style="width: 424px; height: 342px;"><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.sta_title" class="Static sta_WF_PopupTitle" tabindex="-1" style="left:0px;top:0px;width:424px;height:50px;" aria-label="확인 " aria-description="팝업창" status="enabled"><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.sta_title:text" class="nexacontentsbox" style="left:30px;top:0px;width:394px;height:50px;">확인</div></div><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.div_msg" class="Div" tabindex="-1" style="left:18px;top:146px;width:392px;height:108px;" role="document" aria-label=" " aria-description="" aria-labelledby="accessibility_notify_0" status="focused"><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.div_msg.form" class="Form" tabindex="-1" userstatus="contents" status="focused" style="left: 0px; top: 0px; width: 392px; height: 108px;"><div class="nexacontainer" id="nexacontainer" style="width: 392px; height: 108px;"><div class="nexainnercontainer" id="nexacontainer" style="width: 392px; height: 108px;"><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.div_msg.form.sta_msg" class="Static sta_WF_AlertMessage" tabindex="-1" style="left: 8px; top: 0px; width: 360px; height: 108px;" aria-label=" " aria-description="" status="enabled"><div class="nexacontentsbox" id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.div_msg.form.sta_msg:text" style="left: 0px; top: 0px; width: 360px; height: 108px; white-space: pre-wrap; overflow-wrap: break-word; word-break: break-all; text-align: center; vertical-align: middle;">기준일자를 기준으로 예약현황이 새로고침 됩니다.</div></div></div></div><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.div_msg.form.hscrollbar" class="HScrollBarControl hscrollbarForm" tabindex="-1" status="disabled" style="left: 0px; top: 108px; width: 392px; height: 0px; border: 0px none;"><div class="nexasimplecontainer" id="nexacontainer" style="left: 0px; top: 1px;"><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.div_msg.form.hscrollbar.decbutton" class="ButtonControl decbutton" tabindex="-1" status="disabled" style="left: 0px; top: 0px; width: 12px; height: 12px;"><div class="nexacontentsbox" id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.div_msg.form.hscrollbar.decbutton:icontext" style="left: 0px; top: 0px; width: 12px; height: 12px; background-image: url(&quot;./_resource_/_theme_/esky_pc/images/btn_WF_ScrD.png&quot;);"></div></div><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.div_msg.form.hscrollbar.incbutton" class="ButtonControl incbutton" tabindex="-1" status="disabled" style="left: 96px; top: 0px; width: 12px; height: 12px;"><div class="nexacontentsbox" id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.div_msg.form.hscrollbar.incbutton:icontext" style="left: 0px; top: 0px; width: 12px; height: 12px; background-image: url(&quot;./_resource_/_theme_/esky_pc/images/btn_WF_ScrD.png&quot;);"></div></div></div></div><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.div_msg.form.vscrollbar" class="VScrollBarControl vscrollbarForm" tabindex="-1" status="disabled" style="left: 392px; top: 0px; width: 0px; height: 108px; border: 0px none;"><div class="nexasimplecontainer" id="nexacontainer" style="left: 1px; top: 0px;"><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.div_msg.form.vscrollbar.decbutton" class="ButtonControl decbutton" tabindex="-1" status="disabled" style="left: 0px; top: 0px; width: 12px; height: 12px;"><div class="nexacontentsbox" id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.div_msg.form.vscrollbar.decbutton:icontext" style="left: 0px; top: 0px; width: 12px; height: 12px; background-image: url(&quot;./_resource_/_theme_/esky_pc/images/btn_WF_ScrD.png&quot;);"></div></div><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.div_msg.form.vscrollbar.incbutton" class="ButtonControl incbutton" tabindex="-1" status="disabled" style="left: 0px; top: 380px; width: 12px; height: 12px;"><div class="nexacontentsbox" id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.div_msg.form.vscrollbar.incbutton:icontext" style="left: 0px; top: 0px; width: 12px; height: 12px; background-image: url(&quot;./_resource_/_theme_/esky_pc/images/btn_WF_ScrD.png&quot;);"></div></div></div></div></div></div><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.btn_ok2" class="Button btn_WF_CRUD02" tabindex="-1" style="left: 162px; top: 280px; width: 100px; height: 40px;" role="button" aria-label="확인 " aria-description="" status="enabled"><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.btn_ok2:icontext" class="nexacontentsbox" style="left:0px;top:2px;width:100px;height:38px;">확인</div></div><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.btn_ok" class="Button btn_WF_CRUD02" tabindex="-1" style="visibility: hidden; left: 109px; top: 280px; width: 100px; height: 40px;" role="button" aria-label="예 " aria-description=""><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.btn_ok:icontext" class="nexacontentsbox" style="left:0px;top:2px;width:100px;height:38px;">예</div></div><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.btn_cancel" class="Button btn_WF_CRUD01" tabindex="-1" style="visibility: hidden; left: 214px; top: 280px; width: 100px; height: 40px;" role="button" aria-label="아니오 " aria-description=""><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.btn_cancel:icontext" class="nexacontentsbox" style="left:0px;top:2px;width:100px;height:38px;">아니오</div></div><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.btn_close" class="Button btn_WF_PopupClose" tabindex="-1" style="left:374px;top:0px;width:50px;height:50px;" role="button" aria-label="팝업닫기 " aria-description="" status="enabled"><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.btn_close:icontext" class="nexacontentsbox" style="left:0px;top:0px;width:50px;height:50px;background-image:url(./_resource_/_theme_/esky_pc/images/btn_WF_Close02.png);"></div></div><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.sta_bg" class="Static sta_WF_Alert2" tabindex="-1" style="left:0px;top:50px;width:424px;height:80px;" role="document" aria-label=" " aria-description="" aria-labelledby="accessibility_notify_0" status="enabled"></div><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.sta_00" class="Static" tabindex="-1" style="visibility:hidden;left:126px;top:366px;width:224px;height:44px;background:aqua;" role="document" aria-label=" " aria-description="" aria-labelledby="accessibility_notify_0"><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.sta_00:text" class="nexacontentsbox" style="left:0px;top:0px;width:224px;height:44px;">↑ confirm, alert 버튼 겹쳐 있음</div></div><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.sta_01" class="Static" tabindex="-1" style="left:121px;top:321px;width:150px;height:21px;" role="document" aria-label=" " aria-description="" aria-labelledby="accessibility_notify_0"></div></div></div><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.hscrollbar" class="HScrollBarControl hscrollbarForm" tabindex="-1" status="disabled" style="left: 0px; top: 342px; width: 424px; height: 0px; border: 0px none;"><div class="nexasimplecontainer" id="nexacontainer" style="left: 0px; top: 1px;"><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.hscrollbar.decbutton" class="ButtonControl decbutton" tabindex="-1" status="disabled" style="left: 0px; top: 0px; width: 12px; height: 12px;"><div class="nexacontentsbox" id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.hscrollbar.decbutton:icontext" style="left: 0px; top: 0px; width: 12px; height: 12px; background-image: url(&quot;./_resource_/_theme_/esky_pc/images/btn_WF_ScrD.png&quot;);"></div></div><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.hscrollbar.incbutton" class="ButtonControl incbutton" tabindex="-1" status="disabled" style="left: 330px; top: 0px; width: 12px; height: 12px;"><div class="nexacontentsbox" id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.hscrollbar.incbutton:icontext" style="left: 0px; top: 0px; width: 12px; height: 12px; background-image: url(&quot;./_resource_/_theme_/esky_pc/images/btn_WF_ScrD.png&quot;);"></div></div></div></div><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.vscrollbar" class="VScrollBarControl vscrollbarForm" tabindex="-1" status="disabled" style="left: 424px; top: 0px; width: 0px; height: 342px; border: 0px none;"><div class="nexasimplecontainer" id="nexacontainer" style="left: 1px; top: 0px;"><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.vscrollbar.decbutton" class="ButtonControl decbutton" tabindex="-1" status="disabled" style="left: 0px; top: 0px; width: 12px; height: 12px;"><div class="nexacontentsbox" id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.vscrollbar.decbutton:icontext" style="left: 0px; top: 0px; width: 12px; height: 12px; background-image: url(&quot;./_resource_/_theme_/esky_pc/images/btn_WF_ScrD.png&quot;);"></div></div><div id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.vscrollbar.incbutton" class="ButtonControl incbutton" tabindex="-1" status="disabled" style="left: 0px; top: 412px; width: 12px; height: 12px;"><div class="nexacontentsbox" id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.vscrollbar.incbutton:icontext" style="left: 0px; top: 0px; width: 12px; height: 12px; background-image: url(&quot;./_resource_/_theme_/esky_pc/images/btn_WF_ScrD.png&quot;);"></div></div></div></div></div>

, и он не может найти элемент, который я хочу. как я могу исправить?

++ ошибка messege

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="mainframe.childframe.msgPop_51f51eb4-5253-d248-88be-cb5340d14c3a.form.btn_ok2"]"}
  (Session info: chrome=81.0.4044.129)

+++ код кнопки

//*[@id="mainframe.childframe.msgPop_bfe471f6-8b38-2533-802b-cb7e87b13ba5.form.btn_ok2:icontext"]

1 Ответ

0 голосов
/ 30 апреля 2020

Кажется, ваш атрибут id является случайным.

Индуцируйте WebDriverWait () и ждите presence_of_element_located () и последующего селектора css.

WebDriverWait(driver,10).until(EC.presence_of_element_located((By.CSS_SELECTOR ,'[id^="mainframe.childframe.msgPop"][id$="form.btn_ok2"]'))).click()

Вам нужно импортировать следующие библиотеки.

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...