在selenium webdriver

时间:2017-06-21 06:27:16

标签: angularjs selenium automation

请参阅上面的代码并帮助我从下拉列表中选择IBM Software培训。过去1周我遇到了这个问题。由于前端是棱角分明的,没有选择标签,所以我无法选择下拉列表。我没有在笔记本电脑上安装selenium IDE,因为我使用的是Firefox版本52.Selenium IDE不可用对于更高版本。所以,真的很无奈。请帮我解决这个问题。

              <div class="cdk-overlay-container"><div class="cdk-overlay-backdrop cdk-overlay-transparent-backdrop cdk-overlay-backdrop-showing"></div>
    <div id="cdk-overlay-3" class="cdk-overlay-pane" dir="ltr" style="min-width: 503px; pointer-events: auto; top: 108.422px; left: 209px;">
          <div class="mat-select-panel mat-primary mat-select-panel-done-animating" style="transform-origin: 50% 24px 0px; opacity: 1; min-width: calc(100% + 32px); transform: scaleY(1);">
            <div class="mat-select-content" style="opacity: 1;">

                  <!---->
<md-option role="option" tabindex="0" id="md-option-99" aria-selected="false" aria-disabled="false" class="mat-option"><!---->
            IBM Software training3
</md-option>
<md-option role="option" tabindex="0" id="md-option-100" aria-selected="false" aria-disabled="false" class="mat-option"><!---->
            IBM Software training1
</md-option>
<md-option role="option" tabindex="0" id="md-option-101" aria-selected="false" aria-disabled="false" class="mat-option"><!---->
            New Category
</md-option>
<md-option role="option" tabindex="0" id="md-option-102" aria-selected="false" aria-disabled="false" class="mat-option"><!---->
            IBM SOftware trainingggggg
</md-option>
<md-option role="option" tabindex="0" id="md-option-103" aria-selected="false" aria-disabled="false" class="mat-option"><!---->
            IBM Software training
</md-option>
<md-option role="option" tabindex="0" id="md-option-104" aria-selected="false" aria-disabled="false" class="mat-option"><!---->
           qqq
</md-option>
    <md-option role="option" tabindex="0" id="md-option-105" aria-selected="false" aria-disabled="false" class="mat-option"><!---->
            eeeee

</md-option>
<md-option role="option" tabindex="0" id="md-option-106" aria-
    selected="false" aria-disabled="false" class="mat-option"><!---->
                New
</md-option>
<md-option role="option" tabindex="0" id="md-option-
        107" aria-selected="false" aria-disabled="false" class="mat-option"><!---->
                Economics
</md-option>
<md-option role="option" tabindex="0" id="md-option-108" aria-
    selected="false" aria-disabled="false" class="mat-option"><!---->
               IBM
</md-option>


            </div>
          </div>
        </div></div>

5 个答案:

答案 0 :(得分:0)

似乎为所有选项分配了唯一的ID。您是否尝试使用ID点击该选项?

答案 1 :(得分:0)

您可以尝试下面的内容 -

driver.findElement(By.xpath("//div[@class='mat-select-content']//md-option[text()='New Category']")).click();

希望它能奏效。

答案 2 :(得分:0)

您可以尝试以某种方式选择它

library(shiny)
library(shinydashboard)

convertMenuItem <- function(mi,tabName) {
  mi$children[[1]]$attribs['data-toggle']="tab"
  mi$children[[1]]$attribs['data-value'] = tabName
  mi
}

sidebar <- dashboardSidebar(
  sidebarMenu(
    convertMenuItem(menuItem("Query1",tabName="Query1",icon=icon("table"),
             numericInput('Start1','Start Date',19800312,min=20170101,max=20200101),
             numericInput('End1','End Date',19800312,min=20170101,max=20200101),
             textInput('Office1','Office ID','0'),
             submitButton("Submit")), tabName = "Query1"),
    convertMenuItem(menuItem("Query2",tabName="Query2",icon=icon("table"),
             numericInput('Start2','Start Date',20180101,min=20170101,max=20200101),
             numericInput('End2','End Date',20180101,min=20170101,max=20200101),
             textInput('Office2','Office ID','0'),
             submitButton("Submit")), tabName = "Query2")
  )
)
body <- dashboardBody(
  tabItems(
    tabItem(tabName="Query1", h2("Dashboard tab content")),
    tabItem(tabName = "Query2", h2("Widgets tab content"))
  )
)
ui <- dashboardPage(
  dashboardHeader(title = 'LOSS PREVENTION'),
  sidebar,
  body
)

server <- function(input, output) {}
shinyApp(ui, server)

答案 3 :(得分:0)

xpath = //md-option[text() = 'IBM Software training']

我希望这会有所帮助。

您必须先单击下拉字段,然后才能单击下拉值,然后所有下拉值都出现在DOM中。

答案 4 :(得分:0)

问题是,根据所使用的angular版本,解决方案的实现细节将有所不同。它们共享相同的流量。

首先,您需要单击mat-select(或md-select),这样做会填充下拉列表。

现在,而不是使用thread.sleep,您应该改为检查angular是否有任何挂起的http_requests(角度1)或_ngZone是否稳定(角度2)。从电话中回复时,我手头上没有确切的语法,但我相信您可以在此处查找这些语法。

一旦完成了加载部分,则单击选项元素。

请注意,如果下拉列表很长,则可能需要向下滚动到需要单击的元素。