2016-04-29 292 views
0

我想從Chrome瀏覽器中獲取當前網址。當我的瀏覽器使用英語時,我的代碼正在工作。但是當有人使用不同的語言時,由於比較而不起作用。C#如何從Chrome獲取當前網址(多種語言設置)

AutomationElement elm = AutomationElement.FromHandle(p.MainWindowHandle); 
AutomationElement elmUrlBar = null; 

// elmUrlBar = elm.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Adresse und Suchleiste")); 
// if (elmUrlBar != null) 
elmUrlBar = elm.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Address and search bar")); 

if (elmUrlBar != null) 
{ 
    AutomationPattern[] patterns = elmUrlBar.GetSupportedPatterns(); 
    if (patterns.Length > 0) 
    { 
     ValuePattern val = (ValuePattern)elmUrlBar.GetCurrentPattern(patterns[0]); 
     objSchemeDetail.ProcessName = val.Current.Value; 
    } 
} 

我將「地址和搜索欄」改爲德文,但它仍然無效。什麼是替代品?

+0

看起來其他人擁有[相同](https://bugs.chromium.org/p/chromium/issues/detail?id=271227)問題。您可能必須檢查確切翻譯的源代碼。 – wimh

+0

我試過但沒有找到任何源代碼。 –

回答

0

Chrome是由Google提供的Chromium版本。鉻源代碼爲chromium.googlesource.com。搜索「地址欄和搜索欄」我發現generated_resources_en-GB.xtb顯示與標識的英文文本,例如:

<translation id="2824775600643448204">Address and search bar</translation> 

當我在德國的版本(generated_resources_de.xtb)爲同一ID搜索,我發現

<translation id="2824775600643448204">Adress- und Suchleiste</translation> 

所以它看起來像你必須檢查這個文件,你想支持的每種語言。在鉻版本48和更新版本中,這段文字似乎已經轉移到了不同​​的位置。