Find an element by text and get xpath - selenium webdriver junit

后端 未结 11 722
情深已故
情深已故 2020-12-03 04:17

I have a table with 9 rows and 6 columns in my webpage. I want to search for a text \"MakeGoodDisabled-Programwise_09_44_38_461(n)\" and get the xpath of the cell. I have us

11条回答
  •  遥遥无期
    2020-12-03 04:19

    The question which you asked does not make any sense to me. I guess there might be a strong reason for you to 'want to do it' !

    Your line of code

     String xpath = driver.findElement(By.name(test)).getAttribute("xpath");
    

    will not return anything because there is no attribute 'xpath' in html elements. Please get your basics clear on to what xpath means??

    if i have an html element as shown below

    
    

    i can get the values of attribute by using

    driver.findElement(By.name("username").getAttribute("value");  // returns 'Name'
    

    This will give me value of 'value' attribute

    or

    driver.findElement(By.name("username").getAttribute("readonly");  // returns 'readonly'
    

    same as above !

提交回复
热议问题