所以我尝试使用我得到的链接进行foreach,但是foreach内的代码仅适用于第一个链接,此后它不再起作用了,我得到了此错误消息。
$links = $driver->findElements( WebDriverBy::xpath( '//*[@id="ctl00_ContentBody_grvStudentResult"]/tbody/tr/td/span/a' ) );
foreach( $links as $key => $value )
{
$link = $value->getAttribute( 'href' );
$rawPage = $driver->get( $link );
$dados = $rawPage->findElement( WebDriverBy::cssSelector( '#fmvSession tbody tr td h2' ) )->getText();
$a = explode( ': ', $dados );
$b = explode( ', ', $a[ 1 ]);
echo "01: " . trim( $b[ 0 ] ) . "\n";
echo "02: " . trim( $b[ 1 ] ) . "\n";
}
错误消息:
致命错误:未被发现 Facebook \ WebDriver \ Exception \ StaleElementReferenceException:过时 元素参考:元素未附加到页面文档
(会话信息:chrome = 70.0.3538.102)
答案 0 :(得分:2)
当导航到另一个页面import (
"fmt"
"github.com/go-vgo/robotgo"
)
func main() {
// mouse events: mleft, mright, wheelDown, wheelUp, wheelLeft, wheelRight.
mleft := robotgo.AddEvent("mleft")
if mleft == 0 {
fmt.Println("you press... ", "mouse left button")
}
}
不再有效时,您位于新页面中,因此以前定位的WebElement现在已过时。将链接另存为字符串列表并对其进行迭代
$links