简体   繁体   English

Watir-WebDriver:我无法在iframe中单击可见的div

[英]Watir-webdriver: I can't click a visible div in an iframe

I have a facebook app which I'd like to test using Watir. 我有一个我想使用Watir进行测试的Facebook应用程序。 The problem is I can't access its divs. 问题是我无法访问其div。 The is located within an iframe. 位于iframe中。 I can find it and it even says it's visible. 我可以找到它,甚至说它是可见的。 The problem is I can't click it (it says it's invisible when trying) 问题是我无法单击它(它表示尝试时不可见)

Can you help please? 你能帮忙吗? I posted my code with a XXX instead of the user name and a different App for Facebook. 我用XXX(而不是用户名)和其他适用于Facebook的应用程序发布了代码。

Thanks a lot. 非常感谢。

require "watir-webdriver"

browser  = Watir::Browser.new
browser.goto "http://www.facebook.com"

sleep(2)
if browser.text_field(:id => 'pass').exists?
   browser.text_field(:id => 'email').set 'XXXXXXXXX'
   browser.text_field(:id => 'pass').set 'ZZZZZZZ'
   browser.button(:value => 'Log In').click
end
sleep(2)
browser.text_field(:id => 'q').set 'World Of Fun'
browser.send_keys :enter
sleep (2)

browser.goto "https://www.facebook.com/dialog/oauth?client_id=277448022299830&redirect_uri=http%3A//apps.facebook.com/worldoffun/%3Fref%3Dts&canvas=1&fbconnect=0&scope=email,publish_actions"
sleep (2)

if browser.button(:name => 'grant_clicked').exists?
  browser.button(:name => 'grant_clicked').click
  sleep(3)
end
sleep(1)

That's because the element you are trying to identify, is not present on that page, try this instead: 那是因为您要识别的元素不在该页面上,请尝试以下操作:

  if browser.label(:id => 'grant_clicked').exists?
  browser.label(:id => 'grant_clicked').click
  sleep(3)

I also noticed that the app is in flash, so Watir will not be able to handle flash elements within it, i'd recommend using AutoIt or Project Sikuli together with Watir-Webdriver. 我还注意到该应用程序在Flash中,因此Watir将无法处理其中的Flash元素,我建议将AutoItProject Sikuli与Watir-Webdriver一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM