I want to have my web view pannable left and right but not up and down.
Is that possible?
Thanks.
ok, well wrap your one line of html like this:
<html>
<head>
<meta name = "viewport" content = "height = device-height, user-scalable = no, width = WIDTH">
</head>
<body>
...YOUR HTML
</body>
</html>
Replace width with the width of your content, and see how it works.
Related
I'm trying to use Selenium in python with standard and with undetected_chrome drivers in normal and headless browser modes.
I've noticed some strange behaviors:
normal chrome driver works fine with special inputs while sending keys into HTML input field with send_keys() function
undetected_chrome driver does not handle the special inputs very well with send_keys() function
in normal browser mode if I send an email address into a HTML input field, like 'abc#xyz.com' the current content from the clipboard is pasted in place of '#' character
e.g.: if I have copied the string '123' for the last time, the entered email address will not be 'abc#xyz.com' but 'abc123xyz.com' which is obviously incorrect
that's why I'm using a workaround, that I import pyperclip and put '#' character to the clipboard before the send_keys() function runs, to replace the '#' character with '#' character correctly
in headless browser mode if I enter an email address into a HTML input field, like 'abc#xyz.com' my workaround doesn't matter any more, the '#' character will be stripped from the email, and the 'abcxyz.com' string will be put into the field
I think sending a '#' character shouldn't be that hard by default. Am I doing something wrong here?
Questions:
Can anyone explain these strange behaviors?
How could I send an email address correctly with headless browser mode? (I need to use undetected_chrome driver because of bots)
from selenium import webdriver
self.chrome_options = webdriver.ChromeOptions()
if self.headless:
self.chrome_options.add_argument('--headless')
self.chrome_options.add_argument('--disable-gpu')
prefs = {'download.default_directory' : os.path.realpath(self.download_dir_path)}
self.chrome_options.add_experimental_option('prefs', prefs)
self.driver = webdriver.Chrome(options=self.chrome_options)
import undetected_chromedriver as uc
# workaround for problem with pasting text from the clipboard into '#' symbol when using send_keys()
import pyperclip
pyperclip.copy('#') # <---- THIS IS THE WORKAROUND FOR THE PASTING PROBLEM
self.chrome_options = uc.ChromeOptions()
if self.headless:
self.chrome_options.add_argument('--headless')
self.chrome_options.add_argument('--disable-gpu')
self.driver = uc.Chrome(options=self.chrome_options)
params = {
"behavior": "allow",
"downloadPath": os.path.realpath(self.download_dir_path)
}
self.driver.execute_cdp_cmd("Page.setDownloadBehavior", params)
The versions I'm using requirements.txt:
selenium==4.3.0
undetected-chromedriver==3.1.5.post4
Instead of using custom configuration options, try a more basic variant first and see if works correctly. And then figure out which option combination is causing the issue.
An example (which does work correctly by the way)
import undetected_chromedriver as uc
from selenium.webdriver.common.by import By
driver = uc.Chrome()
driver.execute_script("""
document.documentElement.innerHTML = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
html, body, main {
height: 100%;
}
main {
display: flex;
justify-content: center;
}
</style>
</head>
<body>
<main>
<form>
<input type="text" name="text" />
<input type="email" name="email"/>
<input type="tel" name="tel"/>
</form>
</main>
</body>
</html>`
""")
driver.find_element(By.NAME, "text").send_keys("info#example.com")
driver.find_element(By.NAME, "email").send_keys("info#example.com")
driver.find_element(By.NAME, "tel").send_keys("info#example.com")
This complaint (entering "#" pastes clipboard contents) has come up here from time to time but I've never seen a definitive solution. I'd suspect a particular language version of Windows &/or keyboard driver.
The windows language is the problem, more precisley the keyboard layout as it changes depending on language. Switch it to "ENG" and it should work fine. Keyboard layouts where letter Z is between "T" and "U" are not working with undetected driver. Keyboard layout that has Z next to "X" works fine.
This question already has answers here:
Fade out of a Mp3 song using javascript
(2 answers)
Closed 12 months ago.
I really need some help IN All the examples I found the fade out effect was relying on the "audio id" element :
<audio id="myAudio">
<source src="./LZ.mp3" type='audio/mp3'>
</audio>
in all cases my HTA will not play any sound
It seem I can only use the "embed" or even the "bgsound" method
but then I'm lost on applying the needed fade out functions
The following code is the simplified Hta script I use to start a splash together with the mp3 music file.
<html>
<head>
<script language="vbscript">
winWidth=350
winHeight=90
window.resizeto winWidth,winHeight
centerX=(screen.width-winWidth)/2
centerY=(screen.height-winHeight)/2
</script>
</head>
<head>
<HTA:APPLICATION
ID="start"
VERSION="2.0"/>
<body>
<button style=" title="">Starting </button> <p>
</body>
</head>
<script type="text/javascript">
function countdown() {
var i = document.getElementById('start');
{
window.close();
}
}
setInterval(function(){ countdown(); },30000);
</script>
<body>
<embed audio src="./LZ.mp3"></audio >
</body>
</html>
The splash will last 30 secs. and on closing will cut the sounds
I would like to add a fade out effect after 25 secs (5 secs. before the end)
(I cannot apply the fade out effect directly to the mp3 file because very quickly using another script I can chose to use any other mp3 )
the music will auto-start and the fade out effect should be automatic ( I mean no manual buttons)
EDIT: thanks to LesFerch my simplified hta now is playing + the music is closing with the aimed fade out effect. I'm just trying to add again the "Starting" title and the colors effects:
<body>
<button style= title="">Starting Firefox</button> <p>
<script language="VBScript">
Dim Intrval, direction
Dim c 'Used to increment
Function Color(i) : Color = "#" & Hex(i) & Hex(ii) & Hex(i) : end function
Sub Window_Onload
c = &hff
direction = -2
Intrval = setInterval("changeColor", 20)
end sub
sub changeColor
document.body.bgColor = Color(c)
c = (c + direction)
if c > (&hff - Abs(direction)) or c < Abs(direction) then direction = -direction
end sub
</script>
Using the answer in the duplicate link, I made some adjustments to eliminate an IndexSizeError, play the mp3 without a button, and make the fade last a reasonable amount of time. Since your sample code starts off in VBScript, I've assumed that's your preferred language. If not, I can post a JScript version as well.
Note: What makes this, perhaps, not a duplicate is that, for an HTA, the document mode must be declared and set to IE=9 or higher.
Note: Document mode IE=9 and higher are much more case sensitive. For example, screen.availWidth will work, screen.AvailWidth will throw an error.
<!DOCTYPE html>
<html>
<head>
<title>Fade Test</title>
<meta charset="UTF-8" http-equiv="X-UA-Compatible" content="IE=9">
<hta:application
id=oHTA
icon=SndVol.exe
>
<script language="vbscript">
Set oWSH = CreateObject("Wscript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
w = 350
h = 90
window.resizeTo w, h
window.moveTo (screen.availWidth - w)/2, (screen.availHeight - h)/2
MyPath = Mid(document.URL,8)
MyFolder = oFSO.GetParentFolderName(MyPath)
oWSH.CurrentDirectory = MyFolder
Sub window_onLoad
mp3.play
FadeOut
End Sub
Sub FadeOut
If mp3.volume >= 0.1 Then
mp3.volume = mp3.volume - 0.1
window.setTimeout "FadeOut()", 2000
Else
self.close
Exit Sub
End If
End Sub
</script>
<style>
</style>
</head>
<body>
<audio id="mp3">
<source src="./LZ.mp3" type='audio/mp4'>
</audio>
</body>
</html>
I want to display selected value of select() bokeh widget in my browser.
This is my code, where I have data frame and values and that is how my widget gets populated !!!
multi_select = Select (title = "Select Quarters" , value = str1, options = df)
This is how it is calling using this function!!
def function_to_call(attrname, old, new):
print(multi_select.value)
This is my HTML template which will call select value .
text=("""<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
{{ bokeh_css }}
{{ bokeh_js }}
</head>
<body>
<style type="text/css">
{% include 'styles.css' %}
</style>
{{ plot_div|indent(8) }}
{{ plot_script|indent(8) }}
<div>
<h1 style="color:#8CC43F">{selectval}</h1>
</div>
</body>
</html>
""")
Here {selectval} value is replacing my multi_select value from dropdown!!
m =multi_select.on_change('value',function_to_call)
text = text.format(selectval=m)
div = Div(text=text,width=200, height=100)
This is how i am calling the widget
curdoc().add_root(widgetbox(multi_select,div))
After doing this, it is still not displaying the value of my selected option from the select list. For example, if I am selecting Quarter-4 then it should display as text Quarter-4 in my div or textbox on "my browser" screen.
Any help will be appreciated. Thanks in advance !!
In your function you can change the text of the div widget directly
def function_to_call(attrname, old, new):
div.text = new
Here attrname is 'value'
old is the value of the Select widget before it was changed
new is the new value of the Select widget
Original question locates here, current question is desire to avoid one problem.
I have this code which works perfect with html_1 data:
from pyparsing import nestedExpr, originalTextFor
html_1 = '''
<html>
<head>
<title><?php echo "title here"; ?></title>
<head>
<body>
<h1 <?php echo "class='big'" ?>>foo</h1>
</body>
</html>
'''
html_2 = '''
<html>
<head>
<title><?php echo "title here"; ?></title>
<head>
<body>
<h1 <?php echo $tpl->showStyle(); ?>>foo</h1>
</body>
</html>
'''
nested_angle_braces = nestedExpr('<', '>')
# for match in nested_angle_braces.searchString(html):
# print(match)
# nested_angle_braces_with_h1 = nested_angle_braces().addCondition(
# lambda tokens: tokens[0][0].lower() == 'h1')
nested_angle_braces_with_h1 = originalTextFor(
nested_angle_braces().addCondition(lambda tokens: tokens[0][0].lower() == 'h1')
)
nested_angle_braces_with_h1.addParseAction(lambda tokens: tokens[0] + 'MY_TEXT')
print(nested_angle_braces_with_h1.transformString(html_1))
Result of html_1 variable is:
<html>
<head>
<title><?php echo "title here"; ?></title>
<head>
<body>
<h1 <?php echo "class='big'" ?>>MY_TEXTfoo</h1>
</body>
</html>
Here is all right, all placed as expected. MY_TEXT located in right region (inside h1 tag).
But let's see result for html_2:
<html>
<head>
<title><?php echo "title here"; ?></title>
<head>
<body>
<h1 <?php echo $tpl->showStyle(); ?>MY_TEXT>foo</h1>
</body>
</html>
Now we got error, MY_TEXT placed inside h1 property area because PHP contains brace inside "$tpl->".
How I can fix it? I need get this result in that region:
<h1 <?php echo $tpl->showStyle(); ?>>MY_TEXTfoo</h1>
The solution requires that we define a special expression for PHP tags, which our simple nestedExpr gets confused by.
# define an expression for a PHP tag
php_tag = Literal('<?') + 'php' + SkipTo('?>', include=True)
We'll need more than simple strings now for the opener and closer, including a negative lookahead when matching a '<' to make sure we aren't at the leading edge of a PHP tag:
# define expressions for opener and closer, such that we don't
# accidentally interpret a PHP tag as a nested expr
opener = ~php_tag + Literal("<")
closer = Literal(">")
If opener and closer aren't simple strings, then we need to give a content expression too. Our content will be very simple to define, just PHP tags or other Words of printables, excluding '<' and '>' (you'll end up wrapping this all back up in originalTextFor anyway):
# define nested_angle_braces to potentially contain PHP tag, or
# some other printable (not including '<' or '>' chars)
nested_angle_braces = nestedExpr(opener, closer,
content=php_tag | Word(printables, excludeChars="<>"))
Now if I use nested_angle_braces.searchString to scan html_2, I get:
for tag in originalTextFor(nested_angle_braces).searchString(html_2):
print(tag)
['<html>']
['<head>']
['<title>']
['</title>']
['<head>']
['<body>']
['<h1 <?php echo $tpl->showStyle(); ?>>']
['</h1>']
['</body>']
['</html>']
I'm using a Raphael.js on my site. Take a look logo in the header, please. http://hooche.ru/md2
Code for logo:
<script type="text/javascript">
window.onload = function() {
var r = Raphael(logo); r.attr({href: "http://google.com/", target: "blank"});
other vector..
...
</script>
and html-code for logo^
<div id="logo"></div>
But now, we have: 1 letter = 1 Google link = very much Google links and empty, not clickable spaces around letters in one svg-logo.
How to do: 1 svg-logo = 1 link to somewhere with no empty spaces,
for example, div logo have:
width: 190px;
height: 67px;
Replace your div with a link, then you won't need the r.attr() bit either.
<a id="logo" href="http://google.com/"></a>
(I would not advise using target="_blank" there. It's not the standard behaviour. Let the end user choose.)
I think I understand why. I had to do something like this:
<a id="logo" xlink:href="o-nas.php" title=""></a>
xlink
I read in the documentation.