[英]Java Selenium Webdriver set Volume?
Hello I have been looking for a while now but I can't seem to find a way to do this maybe it does not exist? 您好,我已经寻找了一段时间,但似乎无法找到一种方法可能不存在?
I have a java app that use selenium to open a music player from website. 我有一个使用Selenium从网站打开音乐播放器的Java应用程序。 Problem is the player from the website have the sound at max everytime i open it, I would like to be able to set the volume to half or something.
问题是网站上的播放器每次打开时都达到最大音量,我希望能够将音量设置为一半左右。
Now I have seen some people talk about dragging the slider of the player but in this case I can't seem to be able to get the xpath of the player, maybe because it is a player that is embed. 现在,我已经看到有人谈论拖动播放器的滑块,但是在这种情况下,我似乎无法获得播放器的xpath,可能是因为它是嵌入的播放器。
So what I am looking for is a way to change the windows sound that is linked to the new window created by the Webdriver. 因此,我正在寻找一种更改与Webdriver创建的新窗口链接的Windows声音的方法。
Any help would be amazing ! 任何帮助都将是惊人的!
( the player : link if someone wants to check the xpath or whatever ) (玩家: 链接如果有人要检查的XPath或其他)
The idea is to locate the audio
tag and set the volume
property through javascript: 这个想法是找到
audio
标签并通过javascript设置volume
属性:
volume
体积
The playback volume of any audio portions, in the range 0.0 (silent) to 1.0 (loudest).
任何音频部分的播放音量,范围为0.0(静音)到1.0(最大)。
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.presenceOfElementLocated(By.tagName("audio")));
if (driver instanceof JavascriptExecutor) {
((JavascriptExecutor) driver).executeScript("arguments[0].volume = 0.5;", element);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.