有这个html:
<!DOCTYPE html>
<html>
<head>
<meta content="my id" property="fb:app_id" />
<meta content="app name" property="og:site_name" />
<meta content="social post" property="og:type" />
<meta content="bsa" property="og:title" />
<meta content="bsa" property="og:description" />
<meta content="http://will-ferrell.lvh.me:3000/" property="og:url" />
</head>
</html>
尝试这样做:
expect(page).to have_selector :xpath, '//head/meta[@property="fb:app_id"]'
expect(page).to have_selector :xpath, '//head/meta[@property="og:site_name"]'
expect(page).to have_selector :xpath, '//head/meta[@property="og:type"]'
expect(page).to have_selector :xpath, '//head/meta[@property="og:title"]'
expect(page).to have_selector :xpath, '//head/meta[@property="og:description"]'
expect(page).to have_selector :xpath, '//head/meta[@property="og:url"]'
它不起作用。说它找不到选择器。 知道为什么吗?
答案 0 :(得分:1)
对于不可见元素,需要使用option - visible:false
示例:
expect(page).to have_selector :xpath, '//head/meta[@property="og:url"]', visible: false