how to locate an element by value using css selector in webdriver?

后端 未结 6 1509
广开言路
广开言路 2021-01-13 07:10

For the following element, how to find it by the value of the td using css selector? In this case it\'s \"unique text\"



        
相关标签:
6条回答
  • 2021-01-13 07:40

    You may use the CSS method to locate the element by its class name.

    css=".someclass"
    

    See more examples here.

    0 讨论(0)
  • 2021-01-13 07:48

    We can create a XPath something like the below:

    //td[contains(text(), 'unique text')]
    
    0 讨论(0)
  • 2021-01-13 07:53

    You could use something like this,

    With CSS Selector,

     By.cssSelector("td[class='someclass'][value='unique text']");
    

    For more information on using css selector, See here

    0 讨论(0)
  • 2021-01-13 07:55

    WebElement element = driver.findElement(By.cssSelector("input[value='value to be taken']")); //This line is to select Radio Button

    element.click();

    0 讨论(0)
  • 2021-01-13 07:56

    Using the following XPath always gives me expected result and performance. See my another answer here

    //td[.='unique text'] 
    
    0 讨论(0)
  • 2021-01-13 07:58

    You can locate the WebElement either using dynamic xpath or dynamic css

    css-

    WebElement css = driver.findElement(By.cssSelector("td#someclass"));
    

    xpath-

    WebElement xpath = driver.findElement(By.xpath("//td[text,'unique text']"));
    
    0 讨论(0)
提交回复
热议问题