简体   繁体   English

Selenium,W​​ebdriver-找不到-xpath / css_selector /…python

[英]Selenium, webdriver - can't find - xpath/css_selector/… python

Somebody can upload code of clicking the checkbox in this page IN PYTHON ONLY - https://www.google.com/recaptcha/api2/demo 有人可以上传仅在PYTHON中单击此页面中的复选框的代码-https : //www.google.com/recaptcha/api2/demo

i cant find the xpath for this code ... 我找不到此代码的xpath ...

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException

driver1 = webdriver.Firefox()
driver1.get("https://www.google.com/recaptcha/api2/demo")
driver1.find_element_by_xpath(...).click()

if it wasn't clear, i want to click this button ( in the circle ) 如果不清楚,我想单击此按钮(在圆圈中)

在此处输入图片说明

The xpath is //*[@class="recaptcha-checkbox-checkmark"] xpath是//*[@class="recaptcha-checkbox-checkmark"]

The checkbox is inside iframe first you need to switch to the frame then you can find element and click. 复选框位于iframe中,首先您需要切换到框架,然后找到元素并单击。

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException

driver1 = webdriver.Firefox()
driver1.get("https://www.google.com/recaptcha/api2/demo")
driver1.switch_to.frame(driver.find_element_by_css_selector('iframe'))
driver1.find_element_by_xpath('//*[@class="recaptcha-checkbox-checkmark"]').click()

I have tried with java and it is able to click on the checkbox, the java code is given below. 我尝试过使用Java,并且能够单击复选框,下面给出了Java代码。

driver=new FirefoxDriver();
driver.get("https://www.google.com/recaptcha/api2/demo");
driver.switchTo().frame(0);
new WebDriverWait(driver, 120).until(ExpectedConditions.visibilityOf(driver.findElement(By.className("recaptcha-checkbox-checkmark")))).click();

Switching to iFrames catches a lot of people out, but if you have content that is loaded from a different domain (in this case the Captcha) then you need to switch to that with 切换到iFrame会吸引很多人,但是如果您的内容是从其他域(本例中为Captcha)加载的,则需要使用

driver.switchTo().frame(<integer of frame or id>);

Then you will be be able to interact the selector of your choice. 然后,您将能够与您选择的选择器进行交互。

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

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