如何使用硒webdriver在mozilla和chrome浏览器中处理“地理位置"弹出窗口?

编程入门 行业动态 更新时间:2024-10-26 22:23:18
本文介绍了如何使用硒webdriver在mozilla和chrome浏览器中处理“地理位置"弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的问题的屏幕截图如何在mozilla和chrome浏览器使用硒webdriver?

screen shot for my questionHow can I handle Geo Location popup in mozilla and chrome browser using selenium webdriver?

package tiyotesting; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; import org.openqa.selenium.firefox.internal.ProfilesIni; import org.openqa.selenium.support.ui.Select; public class Citydropdownlist { public static void main(String[] args) throws InterruptedException { WebDriver driver = new FirefoxDriver(); driver.get("www.google"); driver.get("ec2-35-154-164-82.ap-south-1pute.amazonaws/tiyorelease3/"); WebElement ListBox = driver.findElement(By.id("supported_city_label")); ListBox.sendKeys("Ahmedabad"); ListBox.sendKeys(Keys.ENTER); } }

我创建了Firefox自定义配置文件,该配置文件也无法再使用,弹出窗口对我来说是最便宜的,所以请帮助我解决问题

I created Firefox custom profile it is also not working again the popup came it is showstopper for me, so please help me to resolve the issue

推荐答案

在使用Selenium 3.x时,geckodriver v0.16.1&在Mozilla Firefox 53.x中,您可以通过在新的Firefox配置文件中设置首选项来禁用地理位置"弹出窗口,如下所示:

While working with Selenium 3.x, geckodriver v0.16.1 & Mozilla Firefox 53.x, you can disable the Geo Location popup by setting the preferences in the new Firefox profile as follows:

  • 您必须从此处下载geckodriver.exe.将其保存在您的计算机上.
  • 您必须提及通过System.setProperty
  • 的geckodriver.exe的绝对路径.
  • 您无需执行driver.get("www.google");即可打开任何其他URL.
  • 这是最小代码的工作集,该代码可以打开预期的URL而没有地理位置"弹出窗口.

  • You have to download the geckodriver.exe from here. Save it on your machine.
  • You have to mention the absolute path of the geckodriver.exe through System.setProperty
  • You don't require to do driver.get("www.google"); to open any other URL.
  • Here is the working set of minimal code which opens the intended URL without the Geo Location popup. System.setProperty("webdriver.gecko.driver", "C:\\your_directory\\geckodriver.exe"); FirefoxProfile geoDisabled = new FirefoxProfile(); geoDisabled.setPreference("geo.enabled", false); geoDisabled.setPreference("geo.provider.use_corelocation", false); geoDisabled.setPreference("geo.prompt.testing", false); geoDisabled.setPreference("geo.prompt.testing.allow", false); WebDriver driver=new FirefoxDriver(geoDisabled); driver.get("ec2-35-154-164-82.ap-south-1pute.amazonaws/tiyorelease3/");

  • 更多推荐

    如何使用硒webdriver在mozilla和chrome浏览器中处理“地理位置"弹出窗口?

    本文发布于:2023-11-27 22:59:46,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1639962.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:如何使用   地理位置   弹出窗口   器中   webdriver

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!