Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Selenium和Python单击登录按钮_Python_Selenium_Selenium Webdriver - Fatal编程技术网

如何使用Selenium和Python单击登录按钮

如何使用Selenium和Python单击登录按钮,python,selenium,selenium-webdriver,Python,Selenium,Selenium Webdriver,如何找到此元素? 我用的是Python。 并且,通过\u css\u选择器()查找\u元素 web源代码来自某个嵌入式机器。所以,我不能用铬。 我在IE上找不到xpath,因为我是初学者 请帮帮我 您可以使用元素的类名单击该元素,您可以这样做: button class="btn btn-primary login-btn" type="button" ng-click="login() 所需元素是一个元素,因此click()您必须引导WebDriverWait使元素成为可单击的()元素,并且

如何找到此元素? 我用的是Python。 并且,
通过\u css\u选择器()查找\u元素

web源代码来自某个嵌入式机器。所以,我不能用铬。 我在IE上找不到xpath,因为我是初学者


请帮帮我

您可以使用元素的类名单击该元素,您可以这样做:

button class="btn btn-primary login-btn" type="button" ng-click="login()
所需元素是一个元素,因此
click()
您必须引导WebDriverWait使
元素成为可单击的()
元素,并且您可以使用以下任一解决方案:

  • 使用
    CSS\u选择器

    button = driver.find_element_by_xpath("//button[text()='Login']")
    button.click()
    
  • 使用
    XPATH

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.btn.btn-primary.login-btn[ng-click^='login']>label.ng-binding[ng-bind$='login']"))).click()
    
  • 注意:您必须添加以下导入:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn btn-primary login-btn' and starts-with(@ng-click, 'login')]/label[@class='ng-binding' and text()='Login']"))).click()
    

您可以在子元素中找到带有“登录”文本的元素。也可以在单击之前向元素添加滚动条

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

要单击的第一个等待元素

element = driver.find_element_by_xpath('//button[label[.="Login"]]')
ActionChains(driver).move_to_element(element).click().perform()
然后使用一些JSExecutor来单击它

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, //button[text()='Login']"")))

谢谢但是,我收到了错误信息。“selenium.common.exceptions.NoSuchElementException:Message:Unable to find element with css selector==.btn btn primary login btn”您不能在
find_element_by_class_name
@KEVIN中使用3个类。我已经编辑了ans。请选择新的答案并告诉我它是否有效谢谢。但是,还是一样。找不到xpath=//button[text()='Login']@KEVIN的元素。请检查html结构中是否存在任何iframe。谢谢。但是,不能单击。消息:无法单击element@KEVIN请用完整的错误堆栈跟踪更新问题。谢谢!但是,同样的信息。消息:无法单击元素谢谢。但是,它不能点击。消息:无法单击check\u response raise exception\u class(Message,screen,stacktrace)selenium.common.exceptions.MoveTargetOutboundsException中第242行的元素文件“D:\Project\Study\Python\venv\lib\site packages\selenium\webdriver\remote\errorhandler.py”element@KEVIN添加
驱动程序。最大化_窗口()
在驱动程序创建之后。谢谢。但是,还是一样。消息:无法单击元素
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, //button[text()='Login']"")))
element = driver.find_element_by_xpath("//button[text()='Login']")
driver.execute_script("arguments[0].click();", element)