I need some Chinese in a form, but running in Linux with Mono it fails. Any tips?
Example:
// works OK in windows and Linux same text.
Console.WriteLine( "Test 中国 的" );
// works OK in windows fails in Linux (renders "Test [][][][]")
MessageBox.Show("Test 中国 的");
// works OK in windows fails in Linux (renders "Test [][][][]")
Textbox1.Text="Test 中国 的"
First, make sure that you have a font set that contains Chinese characters. Then try setting environment var LANG to zh_CN.utf-8 and see if that solves the problem.
Related
I have some tests with WebDriverSampler in Jmeter that work correctly with chromedriver. It is a selenium script that opens a web page and checks that it contains a series of elements. Everything works right until I've tried with the chromedriver headless option.
In this case I get the exception "Expected condition failed: waiting for presence of element located by: By.xpath: ..." as if that element did not exist yet to be loaded. I do not know what can happen, because if I stop using the headless option, if everything works correctly and find the element that really exists.
This is an example of code used(it works without the headless option):
var wait = new support_ui.WebDriverWait(WDS.browser, 30);
var conditions = org.openqa.selenium.support.ui.ExpectedConditions
WDS.sampleResult.sampleStart();
WDS.sampleResult.getLatency();
WDS.browser.get('http://mi-app/');
try{
wait.until(conditions.presenceOfElementLocated(pkg.By.xpath('/ruta_de elemento_existente')));
WDS.log.info('OK')
}catch(e){
WDS.sampleResult.setSuccessful(false);
WDS.sampleResult.setResponseMessage('Fail');
WDS.log.error(e.message)
}
try{
wait.until(conditions.presenceOfElementLocated(pkg.By.xpath('/ruta_de elemento2_existente')));
WDS.log.info('OK2')
}catch(e){
WDS.sampleResult.setSuccessful(false);
WDS.sampleResult.setResponseMessage('Fail2');
WDS.log.error(e.message)
}
WDS.sampleResult.sampleEnd();
I hope someone can help me with this problem, because I need to use the headless option. Thank you very much for your time.
You can print the page source to jmeter.log file by using the following function:
WDS.log.info(WDS.browser.getPageSource())
Or even save it into a separate file like:
org.apache.commons.io.FileUtils.writeStringToFile(new java.io.File('test.html'), WDS.browser.getPageSource())
Or take screenshot on failure like:
WDS.browser.getScreenshotAs(org.openqa.selenium.OutputType.FILE).renameTo(new java.io.File('test.png'))
Check out The WebDriver Sampler: Your Top 10 Questions Answered article for more information.
Also be aware that if the machine where you run your Selenium tests doesn't have GUI you can still normally launch browsers using i.e. Xvfb on Linux or under Local System account on Windows
On Windows 10, you can press Win+Tab to get a "Task View" view of all your windows. I'm trying to check if this is active at any given time. I have tried using a Low Level Keyboard Hook with WH_KEYBOARD_LL but this only allows me to detect the keypress, not if the switcher is active. I've looked at the Windows DWM API and haven't found anything else either.
I have also tried using EnumWindows() and EnumChildWindows(GetDesktopWindow(), ...) and did not find any difference in the output between having the task view shown and hidden.
Is there any accurate method to detect if this is being shown?
Here's a solution that works very consistently with my version of Windows (1709 build 16299.125) and doesn't require the processor-heavy approach of a call to EnumChildWindows:
bool isTaskView() {
//Get foreground window's name
HWND fgWindow = GetForegroundWindow();
TCHAR windowName[MAX_PATH] = L"";
GetWindowText(fgWindow, windowName, MAX_PATH);
//Compare with magic string name of Task View's window
std::wstring nameStr(windowName);
return nameStr == L"Task View";
}
I am new to selenium and I am trying few sites for testing purposes.
Came across a scenario where the tamil and hindi fonts are scrapped as "??????"
I tried to open the output via notepad++, sublimetext and excel but still displays as "??????"
Xpath tried - //h1//following::p[#id='topDescription']
Test URLs
"https://www.hooq.tv/catalog/7a6d593d-e8f3-47b6-92ae-469b8e08178e?__sr=feed"
"https://www.hooq.tv/catalog/d023630f-882b-4df4-8cb5-857ebfff20b4?__sr=feed"
code
d.get("https://www.hooq.tv/catalog/7a6d593d-e8f3-47b6-92ae-469b8e08178e?__sr=feed");
d.findElement(By.xpath("//h1//following::p[#id='topDescription']")).getText();
Is this something about encoding issue ?
First, make sure that you can get the raw text properly before saving it into an external file.
I tested the .getText() in java for your element and it is returning the String as-is.
Next, you need to make sure that during file writing, the charset encoding is UTF-8.
Here's a sample using org.apache.commons.io.FileUtils:
FileUtils.write(new File("C:/temp/test.txt"), str, "UTF-8");
FileUtils.write(new File("C:/temp/test.csv"), str, "UTF-8");
Hope it helps.
I'm trying to get Pango to control FreeType. I've successfully got FreeType to render into a bitmap but Pango doesn't seem to know what's going on, I'm obviously not doing something correctly.
This is the code that I'm using at the moment:
font_map = pango_ft2_font_map_new();
pango_ft2_font_map_set_resolution(PANGO_FT2_FONT_MAP(font_map), 72, 72);
cr = pango_font_map_create_context(PANGO_FONT_MAP(font_map));
font_description = pango_font_description_new ();
pango_font_description_set_family (font_description, "Courier New");
pango_font_description_set_weight (font_description, PANGO_WEIGHT_BOLD);
pango_font_description_set_absolute_size (font_description, 32 * PANGO_SCALE);
layout = pango_layout_new(cr);
pango_layout_set_font_description(layout, font_description);
pango_layout_set_text(layout, "Some sample text!", -1);
pango_context_set_font_description(cr, font_description);
FT_Bitmap bitmap = { 0 };
bitmap.width = drawBitmap.get()->getWidth();
bitmap.rows = drawBitmap.get()->getHeight();
bitmap.pitch = bitmap.width * 4;
bitmap.buffer = (unsigned char*)drawBitmap.get()->getDataPtr();
bitmap.num_grays = 256;
bitmap.pixel_mode = FT_PIXEL_MODE_GRAY;
pango_ft2_render_layout(&bitmap, layout, 100, 100);
drawBitmap is just my helper class, I know this works because I can fill it with random colours and they show up.
This is what gets rendered:
I want to try to get that text to show up properly.
EDIT: The problem has been brought into sharper relief after fixing the bit depth of the image and switching from bare Pango FreeType to Pango Cairo with the FreeType engine.
Using this line:
font_map = pango_cairo_font_map_new_for_font_type(CAIRO_FONT_TYPE_WIN32);
produces
and when I run through pango_font_map_list_families, I get a long list of the fonts installed on my system.
However if I change it to this, to use FreeType:
font_map = pango_cairo_font_map_new_for_font_type(CAIRO_FONT_TYPE_FT);
it produces
and then there are suddenly only 3 fonts on my system, Sans, Serif and Monospace.
I just hit exactly the same issue as yourself but after a lot of digging managed to find a solution that works for me. I've been using the pre-built Pango/FreeType/dependencies libraries from http://www.gtk.org/download/win32.php and copying the runtime DLLs to my exe folder. In the end I had to also copy the '/etc/fonts' folder from the all-in-one version of GTK+ as a subfolder of my exe too. Then suddenly I had fonts via Pango/FreeType! Not sure what the origin of the 'fonts' folder is yet though..
you probably need to tell it where your font files are located manually, freetype alone has no notion of default font locations it's a barebones renderer (and it is really insufficient to display unicode text, that's why other pango engines add other libraries to the mix)
pango-cairo is the most complete pango backend IIRC, and unless I'm wrong it will pull in fontconfig. fontconfig sole purpose is to manage font file locations for apps, that's why it's working out of the box for you
If your chosen backend does use fontconfig try to locate its master conf file and make sure the default directories are appropriate for your system. And then run fc-cache
I want to write an application that will automatically detect and fill the text field in the window shown below:
(assuming the data to be entered is in a file).
The question is how does my application find this text field?
I can do this job if I am able to find the location of the text field on the desktop through program.
Can someone help me understand possible ways for finding this text field?
I am using Windows Form application in C++.
Update:
I played with spy++.
I used spy++, to find the window handle. I did it by putting finder on the window I am interested in. Its giving handle in hex values: 00080086 (actually just for testing purpose I put the finder tool on Visual Studio new project page ). How do I interpret this Hex value into meaningful window name ?
See the below figure.
What is the next step to get to the text field " Enter name" under "name" field.
****Any sample code will be highly appreciated.**
I am open to any solution not necessarily how I am doing this.
One solution is to use the Microsoft UI Automation technology. It's shipped out-of-the-box with Windows since Vista. It's usable from .NET but also from C++ using COM.
Here is a short C++ console application example that displays the class name of the UI Automation Element currently at the middle of the desktop window, each second (you can have it run and see what it displays):
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
IUIAutomation *pAutomation; // requires Uiautomation.h
HRESULT hr = CoCreateInstance(__uuidof(CUIAutomation), NULL, CLSCTX_INPROC_SERVER, __uuidof(IUIAutomation), (LPVOID *)&pAutomation);
if (SUCCEEDED(hr))
{
RECT rc;
GetWindowRect(GetDesktopWindow(), &rc);
POINT center;
center.x = (rc.right - rc.left) / 2;
center.y = (rc.bottom - rc.top) / 2;
printf("center x:%i y:%i'\n", center.x, center.y);
do
{
IUIAutomationElement *pElement;
hr = pAutomation->ElementFromPoint(center, &pElement);
if (SUCCEEDED(hr))
{
BSTR str;
hr = pElement->get_CurrentClassName(&str);
if (SUCCEEDED(hr))
{
printf("element name:'%S'\n", str);
::SysFreeString(str);
}
pElement->Release();
}
Sleep(1000);
}
while(TRUE);
pAutomation->Release();
}
CoUninitialize();
return 0;
}
From this sample, what you can do is launch the application you want to automate and see if the sample detects it (it should).
You could also use the UISpy tool to display the full tree of what can be automated in your target app. You should see the windows and other elements (text field) of this target app and you should see the element displayed by the console application example.
From the pElement discovered in the sample, you can call FindFirst with the proper condition (class name, name, control type, etc...) to get to the text field. From this text field, you would use one of the UI Automation Patterns that should be available (probably TextPattern or ValuePattern) to get or set the text itself.
The cool thing is you can use the UISpy tool to check all this is possible before actually coding it.
You could enumerate windows and then find it.
For exploring application on your screenshot you could you Spy++ (spyxx.exe) that is distributed with visual studio. In you code, you clould use EnumWindows and EnumChildWindows to enumerates all window or all child windows to find one you need.
Although the answer given by Simon is accepted and is the best one, but still for future visitors I am providing this link which has more description for UI automation of windows applications. .
Also for automating a web application one may want to go to this link