我试图通过selenium找出视频进度的价值。我知道我需要找到一种使用java脚本执行器的方法,但还没有发现如何。
这是元素:
<div aria-label="scrub bar" aria-level="polite"
aria-valuemax="100" aria-valuemin="0" class="scrubBar"
role="slider" tabindex="0" aria-valuenow="100%" aria-valuetext="100%%">
<vg-scrub-bar-current-time _ngcontent-c27="">
<div class="background" style="width: 100%;"></div><!---->
</vg-scrub-bar-current-time>
<vg-scrub-bar-buffering-time _ngcontent-c27="">
<div class="background" style="width: 100%;"></div>
</vg-scrub-bar-buffering-time>
</div>
valuenow =&#34; 100%是我想要监控的(我想知道它何时达到100%以触发另一个动作)。
任何帮助都将受到高度赞赏。
答案 0 :(得分:0)
我不知道如何使用JavaScriptExecutor找到它,既不是Java专家。话虽如此,根据信息,我将等待下面显示的那个元素,一旦发现突然出现并启动另一个动作
这不是您正在寻找的答案,但是可能会或可能不会帮助您提出解决方案
转换为Java语法
while True:
percentage = driver.find_element_by_css_selector('div[aria-label="scrub bar"]').get_attribute('aria-valuenow')
if percentage == '100%':
break
我喜欢Andrei Suvorkov给出的答案,
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[Test]
@Level INT,
@KatSubkatId INT,
@WordId INT,
@SubsubkatId INT = NULL
AS
BEGIN
SET NOCOUNT ON;
DECLARE @temp_T_Html_Word_Categories TABLE(Id INT)
DECLARE @temp_T_Html_WordCat_Phrase TABLE(FK_Phrase_ID INT)
IF (@Level = 2)
BEGIN
INSERT INTO @temp_T_Html_Word_Categories(Id) SELECT Id FROM T_Html_Word_Categories WHERE FK_KatSubkat_ID = @KatSubkatId And FK_Word_ID = @WordId
END
ELSE IF (@Level = 3)
BEGIN
INSERT INTO @temp_T_Html_Word_Categories(Id) SELECT Id FROM T_Html_Word_Categories WHERE FK_KatSubkat_ID = @KatSubkatId And FK_Word_ID = @WordId And FK_Subsubkat_ID IS NULL;
INSERT INTO @temp_T_Html_Word_Categories(Id) SELECT Id FROM T_Html_Word_Categories WHERE FK_KatSubkat_ID = @KatSubkatId And FK_Word_ID = @WordId And FK_Subsubkat_ID = @SubsubkatId;
END
ELSE
BEGIN
SELECT null;
RETURN;
END
print 'I am here'
INSERT INTO @temp_T_Html_Word_Categories(Id) SELECT Id FROM T_Html_Word_Categories WHERE FK_KatSubkat_ID = @KatSubkatId And FK_Word_ID = @WordId
--DECLARE @v XML = (SELECT * FROM @temp_T_Html_Word_Categories FOR XML AUTO)
Declare @Id int;
--it makes no difference what you SELECT in an EXISTS sub-query as it is just syntactical sugar. (ie Nothing is actually selected.) SELECT * or SELECT 1 ...
WHILE EXISTS(SELECT * FROM @temp_T_Html_Word_Categories)
BEGIN
Select Top 1 @Id = Id From @temp_T_Html_Word_Categories;
INSERT INTO @temp_T_Html_WordCat_Phrase(FK_Phrase_ID) SELECT FK_Phrase_ID FROM T_Html_WordCat_Phrase WHERE FK_Word_Categorie_ID = @Id;
Delete @temp_T_Html_Word_Categories Where Id = @Id;
END;
--IF EXISTS (SELECT * FROM T_Html_Phrase WHERE Id NOT IN (SELECT FK_Phrase_ID FROM @temp_T_Html_WordCat_Phrase))
-- SET @IddD = 1;
--ELSE
-- SET @IddD = 0;
SELECT * FROM T_Html_Phrase WHERE Id NOT IN (SELECT FK_Phrase_ID FROM @temp_T_Html_WordCat_Phrase)
--DECLARE @b XML = (SELECT * FROM T_Html_Phrase FOR XML AUTO)
Delete @temp_T_Html_WordCat_Phrase;
END
答案 1 :(得分:0)
JavaScript代码:
String value = (String) js.executeScript("return document.getElementByXpath(\"//*[@id=\"cdk- accordion-child-15\"]/div/app-sensors-video/app-cognata-video/vg- player/vg-scrub-bar/div).getAttribute(\"aria-valuenow\")");
为您提供aria-valuenow
的值。
更新:
Java代码:
// elem is WebElement
elem.findElement(By.xpath("//*[@id='cdk- accordion-child-15']/div/app-sensors-video/app-cognata-video/vg- player/vg-scrub-bar/div"));
String s = (String) elem.getAttribute("aria-valuenow");