Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x python+;selenium:通过单击选择日历控件时,元素不可见_Python 3.x_Selenium Webdriver - Fatal编程技术网

Python 3.x python+;selenium:通过单击选择日历控件时,元素不可见

Python 3.x python+;selenium:通过单击选择日历控件时,元素不可见,python-3.x,selenium-webdriver,Python 3.x,Selenium Webdriver,我正在使用python selenium,当单击日历控件时,它显示元素不可见。我尝试了几种方法,如JavaScript executor、explicit wait condition、,正在创建唯一的xpath,但无法单击并打开日历。它位于iframe下。是否有人面临此问题或有解决方案?提前感谢。这是HTML代码片段 <td xpath="1"> <input name="ctl00$ContentPlaceHolder1$txtDateOfB

我正在使用python selenium,当单击日历控件时,它显示元素不可见。我尝试了几种方法,如JavaScript executor、explicit wait condition、,正在创建唯一的xpath,但无法单击并打开日历。它位于iframe下。是否有人面临此问题或有解决方案?提前感谢。这是HTML代码片段

<td xpath="1">

<input name="ctl00$ContentPlaceHolder1$txtDateOfBirth" type="text" maxlength="10" id="ctl00_ContentPlaceHolder1_txtDateOfBirth" class="TextBox" autocomplete="off" style="width:70px;" xpathtest="1">

<input type="image" name="ctl00$ContentPlaceHolder1$ibDateOfBirth" id="ctl00_ContentPlaceHolder1_ibDateOfBirth" src="../Images/minical.gif" onclick="javascript:showCalendarControl(document.getElementById('ctl00_ContentPlaceHolder1_txtDateOfBirth'));return false;WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ContentPlaceHolder1$ibDateOfBirth&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" style="">

<span id="ctl00_ContentPlaceHolder1_rfvDateOfBirth" title="Required" style="color:Red;display:none;">*</span><span id="ctl00_ContentPlaceHolder1_rvDateOfBirth" title="Invalid data" style="color:Red;display:none;">*</span>
 </td>
即使使用xpath,也无法选择,如下所示

File "D:/New folder/SeleniumwithAMBS/calenderpage.py", line 56, in <module>
    driver.find_element_by_xpath("//div[@id='CalendarControl']/table/tbody/tr[9]/th/a[@href='javascript:hideCalendarControl();']").click()
  File "D:\New folder\SeleniumwithAMBS\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "D:\New folder\SeleniumwithAMBS\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "D:\New folder\SeleniumwithAMBS\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "D:\New folder\SeleniumwithAMBS\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
  (Session info: chrome=85.0.4183.83)
  (Driver info: chromedriver=2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),platform=Windows NT 10.0.18363 x86_64)


Process finished with exit code 1
文件“D:/New folder/SeleniumwithAMBS/calenderpage.py”,第56行,在
驱动程序。通过xpath(//div[@id='CalendarControl']/table/tbody/tr[9]/th/a[@href='javascript:hideCalendarControl();'])查找元素。单击()
文件“D:\New folder\SeleniumwithAMBS\venv\lib\site packages\selenium\webdriver\remote\webelement.py”,第80行,单击
self.\u执行(命令。单击\u元素)
文件“D:\New folder\SeleniumwithAMBS\venv\lib\site packages\selenium\webdriver\remote\webelement.py”,第633行,在执行中
返回self.\u parent.execute(命令,参数)
文件“D:\New folder\SeleniumwithAMBS\venv\lib\site packages\selenium\webdriver\remote\webdriver.py”,第321行,在execute中
self.error\u handler.check\u响应(响应)
文件“D:\New folder\SeleniumwithAMBS\venv\lib\site packages\selenium\webdriver\remote\errorhandler.py”,第242行,在check\u响应中
引发异常类(消息、屏幕、堆栈跟踪)
selenium.common.exceptions.ElementNotVisibleException:消息:元素不可见
(会话信息:chrome=85.0.4183.83)
(驱动程序信息:chromedriver=2.38.552522(437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),平台=Windows NT 10.0.18363 x8664)
进程已完成,退出代码为1

如果要选择的元素位于iframe下,则需要选择它:

driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))
请提供指向您要选择的页面的链接,以便我们可以验证为什么您的代码找不到它

  • 切换到ifrmae: driver.switch_to.frame(driver.find_element_by_tag_name(“iframe”))

  • 等待元素显示,并使用一个唯一的id,如下面的XPath。我可以找到元素(在您提供的HTML中)。请参考以下屏幕打印

  • 我可以在HTML中看到“单击”操作,您提供的id指向单击时的参考id“show CalenderControl”,而错误指向参考“hideCalendarControl”。请确认您是否在第一次单击showCalendarControl和稍后单击HideCalendarControl等操作中遵循顺序
  • a。如果未遵循顺序,则可能需要单击启动showCalenderControl

    b。如果我假设您遵循了顺序,那么我的猜测是showCalendarControl将打开控件并在执行步骤之前消失


    如果没有帮助,请分享完整的HTML和代码。

    尝试更好地格式化您的问题。这是不可读的。请你再检查一次好吗?之前我做了那个,切换到帧,但之后我不能
    driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))