我将如何使用Java与SeleniumWebDriver中的这个输入框交互?
我无法让它选择输入名称uxCompanyName。我尝试过使用xpath、selenium IDE和by.id、name等。这些都不适合我。任何帮助都将不胜感激。谢谢 我的剧本:我将如何使用Java与SeleniumWebDriver中的这个输入框交互?,java,javascript,selenium,xpath,webdriver,Java,Javascript,Selenium,Xpath,Webdriver,我无法让它选择输入名称uxCompanyName。我尝试过使用xpath、selenium IDE和by.id、name等。这些都不适合我。任何帮助都将不胜感激。谢谢 我的剧本: WebElement element = (WebElement) ((JavascriptExecutor)driver).executeScript("document.getElementById('uxCompanyName').focus();"); element.findElement(By.i
WebElement element = (WebElement) ((JavascriptExecutor)driver).executeScript("document.getElementById('uxCompanyName').focus();");
element.findElement(By.id("uxCompanyName")).clear();
element.findElement(By.id("uxCompanyName")).sendKeys("password");
HTML:
公司名称:
Selenium在帧方面有问题。
试一试
然后抓住下面的元素,代码应该适合您:
WebDriverWait wait = new WebDriverWait(driver,10);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("bottom"));
element.findElement(By.id("uxCompanyName")).clear();
element.findElement(By.id("uxCompanyName")).sendKeys("password");
它将等待帧,切换到帧,然后与其中的元素交互。@Pradish。。无法检测id为“uxCompanyName”的WebElement的原因是该元素不在当前帧中。如果您再次遇到相同的问题,那么在对WebElement执行任何操作之前,只需在下面一行中包含。“assertTrue(driver.getPageSource().contains(“uxCompanyName”));”uxCompanyName可以由WebElement的任何唯一标识替换。如果为真,则将继续进行,如果不是,则脚本将停止在同一行。这表示所需的WebElement不在框架中,然后您可以查找该页面上可用的框架
希望这能帮助您找出原因和解决方案。这是完整的脚本还是需要添加到某些内容中?谢谢,Kyle。它稍微修改了一下就起作用了。我不确定您的代码块是用什么编写的,但我使用了以下代码:driver.switchTo().frame(“底部”);findElement(By.xpath(//input[@name='uxCompanyName'])).sendKeys(“moneta”);谢谢你的回答,苏里亚。我在回复Kyle.Okay时使用了.switchto命令。好。“FrameToBeAvailable和SwitchToIt”也将执行相同的操作,它将等待帧加载,然后切换到它。它是切换到帧的更可靠的方式,因为一些时间帧需要时间才能完全加载。谢谢,鲁佩什!这是一个简洁的小检查。@Pradishuhiet:如果你认为这个答案对你的问题有帮助,那么请投上一票。我想我需要更多的代表来投你一票。一旦我有了这个能力,我一定会回来的。
getWebDriver().switchTo().frame( getElementById( "frameId" ) );
WebDriverWait wait = new WebDriverWait(driver,10);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("bottom"));
element.findElement(By.id("uxCompanyName")).clear();
element.findElement(By.id("uxCompanyName")).sendKeys("password");