问题
I am trying to select a value in a dropdown which is inside a iFrame. The frame is nested within a table. HTML:
<html class ="some text">
<head>...</head> <body id="htmlBody">
<div class= "modalWindow ui-dialog-content ui-widget-content ModalWindow containsFrame" id="ui-id-2">
<iframe src= "/MyApplicantPortal/Applicant/254471/SelectOrderTemplate?t=1">
#document
<html class = "some text"
<head id= "Head1">
<body id="htmlBody">
<form method= "post" action="SelectOrderTemplate?t=1" id="form1">
<div class = "ModalContent">
<Table>
<td class="label1">
<Select id= "MyselList" </td>
My code:
element(:select_frame, :frame, :src => MyApplicantPortal\/Applicant\/\d+\/SelectOrderTemplate\?t=1/)
select_list(:template) {select_frame_element.select_list_element(:id => 'MyselList')}
Error:
Watir::Exception::UnknownFrameException: unable to locate frame using {:src=>/MyApplicantPortal\/Applicant\/\d+\/SelectOrderTemplate\?t=1/, :tag_name=>"frame"}
回答1:
Watir-webdriver 0.6.5 has changed the way locating frames works.
- Before (ie pre-0.6.5),
browser.framelocatedframeandiframeelements. - Now,
browser.framelocatesframeelements andbrowser.iframelocatesiframeelements.
You will need to change your frame accessor to match the new rules (when you migrated to 0.6.5 or later). The second parameter needs to change from :frame to :iframe:
element(:select_frame, :iframe, :src => /MyApplicantPortal\/Applicant\/\d+\/SelectOrderTemplate\?t=1/)
回答2:
I am in the process of releasing a new version of the page-object gem that addresses this issue. Should be out in a day or two.
来源:https://stackoverflow.com/questions/21533962/accessing-elements-from-within-a-iframe-fails-in-watir-webdriver-0-6-6-works