How to locate and type something in the textbox

后端 未结 4 2021
旧巷少年郎
旧巷少年郎 2020-12-12 06:03
public class testFluent {   

WebDriver driver;   
    @Before
        public void setUp(){        
    driver = new FirefoxDriver();
    driver.manage().window().ma         


        
4条回答
  •  北海茫月
    2020-12-12 07:05

    Regarding your By.id statement, it looks like you have passed an XPath instead of just the id. So this:

    element = myDynamicElement(By.id("//*[@id='p_13838465-p']")); //this locator is an XPath
    

    should become this:

    element = myDynamicElement(By.id('p_13838465-p')); //this is just the ID
    

    However, if this ID is dynamically generated, then it won't work reliably, and you may need to considering finding it by a different locator.

    Then, once you've identified the element, to type in it, you use .sendKeys("your text here"), like this:

    element.sendKeys("your text here");
    

    or you could combine it into one line by skipping the element = part and just say:

    myDynamicElement(By.id('p_13838465-p')).sendKeys("your text here");
    

提交回复
热议问题