selenium:通过python选择div标记和文本

selenium:通过python选择div标记和文本,python,web-applications,selenium,Python,Web Applications,Selenium,几小时前我开始学习硒。我有这样的div标签 <div id="first"> <iframe src="/emulator/" scrolling="no" frameborder="0"></iframe> </div> <div id="second"> //some more html tags </div> 在您的示例中,在div标记中有一个iframe。在Web驱动程序中,如果您想在框架内执行任何操

几小时前我开始学习硒。我有这样的div标签

 <div id="first">
 <iframe src="/emulator/" scrolling="no" frameborder="0"></iframe>
 </div>
 <div id="second">
 //some more html tags
  </div>

在您的示例中,在
div
标记中有一个
iframe
。在Web驱动程序中,如果您想在框架内执行任何操作,则意味着首先yiu必须进入框架内

进入框架的代码:

 driver.switch_to_frame("Frame Name");
 //Do some actions on the frame
driver.switch_to_default_content();
一旦您完成了框架中的操作,您就必须离开框架来执行任何其他操作

离开框架的代码:

 driver.switch_to_frame("Frame Name");
 //Do some actions on the frame
driver.switch_to_default_content();
试试这个

driver.find_element_by_xpath("//div[@id='second']//input").send_keys("your Text here");