2017-06-02 41 views
1

screen shot for my question如何使用硒webdriver處理mozilla和chrome瀏覽器中的地理位置彈出窗口?如何在使用硒webdriver的mozilla和chrome瀏覽器中處理地理位置彈出窗口?

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("http://www.google.com"); 
      driver.get("http://ec2-35-154-164-82.ap-south-1.compute.amazonaws.com/tiyorelease3/"); 
      WebElement ListBox = driver.findElement(By.id("supported_city_label")); 
      ListBox.sendKeys("Ahmedabad"); 
      ListBox.sendKeys(Keys.ENTER); 
     } 
    } 

我創建Firefox的自定義配置文件它也不會再工作彈出來了對我來說是攪局者,所以請幫我解決這個問題

+0

我創建Firefox的自定義配置文件它也沒有工作又彈出來了對我來說是攪局者,所以請幫我解決這個問題 –

+0

進出口無法看到的地理位置彈出google.com的 - 它自動重定向我。請考慮爲彈出窗口提供屏幕截圖。 – iamkenos

+0

我必須附上檔案 –

回答

1

雖然與硒3.X,geckodriver V0工作。 16.1 & Mozilla Firefox瀏覽器53.x,您可以通過設置新的Firefox配置文件中的首選項如下禁用廣告位置彈出:

  1. 你必須從here下載geckodriver.exe。將它保存在你的機器上。
  2. 你必須通過System.setProperty
  3. 提geckodriver.exe的絕對路徑,您不需要做driver.get("http://www.google.com");打開任何其他網址。
  4. 下面是最小代碼的工作集,它打開了沒有地理位置彈出窗口的預期網址。

    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("http://ec2-35-154-164-82.ap-south-1.compute.amazonaws.com/tiyorelease3/"); 
    
+0

非常感謝您先生....它爲我工作 –

+0

先生我有一個問題,相同的代碼...我怎樣才能在列表框中選擇項目?請幫助我@DebanjanB –

+0

感謝您的建議Sir @DebanjanB –

相關問題