本文目錄一覽:
自動化測試中怎麼獲取frame頁面上的元素
frame存在兩種:嵌套,非嵌套
根據元素id或index切換frame:driver.switch_to.frame()
切換到默認frame:driver.switch_to.default_content()
切換到父級frame:driver.switch_to.parent_frame()
切到frame頁:
1.處理未嵌套的frame:
driver.switch_to_frame(“frame的id”)
driver.switch_to_frame(“frame-index”)frame無ID時依據索引來處理,索引從0開始driver.switch_to_frame(0)
2.處理嵌套frame:
對於嵌套的先進入到iframe的父節點,再進到子節點,然後可以對子節點裡面的對象進行處理和操作
driver.switch_to.frame(“父節點”)
driver.switch_to.frame(“子節點”)
switch_to.parent_frame()
switch_to.default_content()
測試頁面:
以獲取frame頁面元素為例:
php獲取指定網頁內容
一、用file_get_contents函數,以post方式獲取url
?php
$url= ”;
$data= array(‘foo’= ‘bar’);
$data= http_build_query($data);
$opts= array(
‘http’= array(
‘method’= ‘POST’,
‘header’=”Content-type: application/x-www-form-urlencoded\r\n” .
“Content-Length: ” . strlen($data) . “\r\n”,
‘content’= $data
)
);
$ctx= stream_context_create($opts);
$html= @file_get_contents($url,”,$ctx);
二、用file_get_contents以get方式獲取內容
?php
$url=”;
$html= file_get_contents($url);
echo$html;
?
三、用fopen打開url, 以get方式獲取內容
?php
$fp= fopen($url,’r’);
$header= stream_get_meta_data($fp);//獲取報頭信息
while(!feof($fp)) {
$result.= fgets($fp, 1024);
}
echo”url header: {$header} br”:
echo”url body: $result”;
fclose($fp);
?
四、用fopen打開url, 以post方式獲取內容
?php
$data= array(‘foo2’= ‘bar2′,’foo3’=’bar3’);
$data= http_build_query($data);
$opts= array(
‘http’= array(
‘method’= ‘POST’,
‘header’=”Content-type: application/x-www-form-
urlencoded\r\nCookie:cook1=c3;cook2=c4\r\n” .
“Content-Length: ” . strlen($data) . “\r\n”,
‘content’= $data
)
);
$context= stream_context_create($opts);
$html= fopen(‘;id2=i4′,’rb’,false, $context);
$w=fread($html,1024);
echo$w;
?
五、使用curl庫,使用curl庫之前,可能需要查看一下php.ini是否已經打開了curl擴展
?php
$ch= curl_init();
$timeout= 5;
curl_setopt ($ch, CURLOPT_URL, ”);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents= curl_exec($ch);
curl_close($ch);
echo$file_contents;
?
用PHP如何獲取網頁審查元素中的內容?
使用file_get_contents可以獲取網頁源碼
?php
$homepage = file_get_contents ( ” );
echo $homepage ;
?
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/258525.html