How to get text of an element on the basis of other element's text value on the same row in the table?

前端 未结 1 876
猫巷女王i
猫巷女王i 2021-01-26 19:50

I need to find the text of an element \"score\" on the basis of other element \"SF Lead ID\" on the same row.

\"SF Lead ID\" can be dynamic. for example am using hard c

相关标签:
1条回答
  • 2021-01-26 20:19

    To extract the score with respect to SF Lead ID you have to induce WebDriverWait for the visibilityOfElementLocated() and you can use either of the following Locator Strategies:

    • Using cssSelector and getText():

      String sf_id = "00Q1l000003clVhEAI";
      System.out.println(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("tr[data-sf-lead-id='" + sf_id + "'] td#lead-score"))).getText());
      
    • Using xpath and getAttribute():

      String sf_id = "00Q1l000003clVhEAI";
      System.out.println(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//tr[@data-sf-lead-id='" + sf_id + "']//td[@id='lead-score']"))).getAttribute("innerHTML"));
      
    0 讨论(0)
提交回复
热议问题