Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Selenium和Java单击元素_Java_Selenium_Xpath_Css Selectors_Webdriverwait - Fatal编程技术网

如何使用Selenium和Java单击元素

如何使用Selenium和Java单击元素,java,selenium,xpath,css-selectors,webdriverwait,Java,Selenium,Xpath,Css Selectors,Webdriverwait,在上面的站点中,点击右上角最后三位的Anmelden链接。 我无法定位电子邮件xpath,因为它是框架的一部分 在下面尝试过,但没有运气 driver.switchTo().frame(0) driver.switchTo().frame(“cbox1556878105885”) driver.switchTo().frame(“cboxIframe”) driver.switchTo().frame(通过xpath(//xpath)查找元素) 要单击位于右上角的元素(即最后第三个项目),然后向

在上面的站点中,点击右上角最后三位的Anmelden链接。 我无法定位电子邮件xpath,因为它是框架的一部分

在下面尝试过,但没有运气

  • driver.switchTo().frame(0)
  • driver.switchTo().frame(“cbox1556878105885”)
  • driver.switchTo().frame(“cboxIframe”)
  • driver.switchTo().frame(通过xpath(//xpath)查找元素)

  • 要单击位于右上角的元素(即最后第三个项目),然后向电子邮件字段发送字符序列,您需要诱导WebDriverWait使该元素可单击,并且您可以使用以下任一解决方案:

    • css选择器

      driver.get("https://shop.medtronic-diabetes.ch/");
      new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.cssSelector("li.firstRow a[title='Anmelden']"))).click();
      new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("iframe.cboxIframe")));
      new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.signInboxInputFields#j_username"))).sendKeys("Mohit_Garg");
      
    • xpath

      driver.get("https://shop.medtronic-diabetes.ch/");
      new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//li[@class='firstRow']//a[text()='Anmelden']"))).click();
      new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[@class='cboxIframe']")));
      new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='signInboxInputFields required' and @id='j_username']"))).sendKeys("Mohit_Garg");
      
    • 浏览器快照:


    尝试使用下面的定位器

         Driver.Navigate().GoToUrl("https://shop.medtronic-diabetes.ch/");
         WebDriverWait webDriverWait = new WebDriverWait(Driver, TimeSpan.FromSeconds(30));
         var loginElement = webDriverWait.Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("div[class='registerNow firstChild'] a[title='Anmelden']")));
         loginElement.Click();
         webDriverWait.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.ClassName("cboxIframe")));
         var email = webDriverWait.Until(ExpectedConditions.ElementToBeClickable(By.Id("j_username")));
         email.SendKeys("Rd@test.com");
    
    建议切换到iframe的方法是使用webdriverwait-ExpectedConditions.FrameToBeAvailable和SwitchToIt等预期条件。 如果您有iframe的ID,则使用
    Driver.SwitchTo().Frame(“frameID”)


    要选择页面上的第一帧或主文档,请使用
    Driver.SwitchTo().DefaultContent()或要选择父帧,请使用
    Driver.SwitchTo().ParentFrame()

    给定URL上不存在Anmelden。只需检查并更新URL。我收到
    发生系统错误
    异常,我的系统错误以及更新的url@cruisepandey,Adi Ohana。抱歉,抱歉,我的问题现在还不太清楚。实际上,我想在登录弹出窗口中访问电子邮件选项。@Mohit Garg我已经编辑了答案