【问题标题】:How to find a web-element如何找到网络元素
【发布时间】:2019-07-30 15:33:30
【问题描述】:

在网页上找不到元素https://cloud.google.com/products/calculator/

需要在上述网页中找到“GPU 数量”网页元素,单击它并从弹出的下拉菜单中选择“1”。

我试过这个 Xpath:

//*[@placeholder='Number of GPUs'] 

但是 webDriver 看不到它:

ElementException: no such element: Unable to locate element: {"method":"xpath","selector":"/*[@placeholder='Number of GPUs']"}

前提条件:

  1. 机器类型:n1-standard-8(vCPU:8,RAM:30GB)
  2. “添加 GPU”复选框已选中

【问题讨论】:

    标签: java selenium selenium-webdriver webdriver webdriverwait


    【解决方案1】:

    要定位并单击与标签关联的元素为 GPU 数量,因为所需元素是 Angular 元素,您必须为 element_to_be_clickable() 诱导 WebDriverWait您可以使用以下任一解决方案:

    • 使用XPATH:

      new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//label[text()='Number of GPUs']//following::md-select-value[@class='md-select-value' and starts-with(@id, 'select_value_label')][1]/span/div[@class='md-text ng-binding']"))).click();
      

    【讨论】:

    • 如果这个/任何答案对您有帮助/对您未来的读者有帮助,请投票赞成。
    【解决方案2】:

    可能最简单的方法是使用下面的 CSS 选择器

    md-select[placeholder='Number of GPUs']
    

    您可能需要先添加一个等待,因为单击“添加 GPU”复选框会显示该下拉列表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-27
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多