如何找到使用类名找到的元素的ID(Python Selenium)

时间:2019-11-23 02:59:03

标签: python python-3.x selenium

我使用类

存储了元素列表

<?php require_once "../../config/configPDO.php"; require_once "../../config/check.php"; $team = $_SESSION['team']; $badgeid = ''; $fullname = ''; $roles_id = ''; function getPosts() { $posts = array(); $posts[0] = $_POST['badgeid']; $posts[3] = $_POST['fullname']; $posts[4] = $_POST['roles_id']; return $posts; } if(isset($_POST['search'])) { $data = getPosts(); if(empty($data[0])) { echo " <script>alert('Please enter badge id')</script>"; } else { $searchStmt = $conn->prepare('SELECT * FROM users WHERE badgeid = :badgeid AND roles_id = "4"'); $searchStmt->execute(array( ':badgeid'=> $data[0] )); if($searchStmt) { $user = $searchStmt->fetch(); if(empty($user)) { echo " <script>alert('No data')</script>"; } $badgeid = $user[0]; $fullname = $user[3]; $roles_id = $user[4]; } } }

但是,我想知道是否可以找到这些元素中每个元素的ID。

我使用Python并正在使用硒。

1 个答案:

答案 0 :(得分:0)

您可以使用console.log("Starting Game"); var canvas = document.querySelector('#tela'); var stageCollor = 'black'; var ballColor = 'grey'; console.log(canvas); var stage = canvas.getContext('2d'); var ball = canvas.getContext('2d'); drawStage(); let distanceFromCenter = 0; let startWidth = canvas.width/2; let startHeight = canvas.height/2; let ballRadius = 10; let startAngle = 0; let endAngle = 2 * Math.PI; let turnedAngle = 0; let piTurnedAngle= 0; ball.arc(startWidth, startHeight, ballRadius, startAngle, endAngle); ball.stroke();//draw ball.fillStyle = ballColor; ball.lineWidth = 1; ball.fill(); setInterval(move,40);//magic function move() { //drawStage(); turnedAngle = turnedAngle +5; piTurnedAngle = turningMovement(turnedAngle); distanceFromCenter = distanceFromCenter +0.0125; startWidth = startWidth + distanceFromCenter*Math.cos(piTurnedAngle); startHeight = startHeight - distanceFromCenter*Math.sin(piTurnedAngle); drawBall(); } function drawBall() { ball.arc(startWidth, startHeight, ballRadius, startAngle, endAngle); ball.stroke();//draw ball.fillStyle = ballColor; ball.lineWidth = 1; ball.fill(); console.log('d - ' + startWidth); } function eraseBall() { ball.arc(startWidth, startHeight, ballRadius, startAngle, endAngle); ball.stroke();//draw ball.fillStyle = stageCollor; ball.lineWidth = 1; ball.fill(); console.log('e - ' + startWidth); } function drawStage(){ canvas.width = 800; canvas.height = 600; stage.fillStyle = stageCollor; stage.fillRect(0,0,canvas.width, canvas.height); stage.beginPath(); } function turningMovement(angle){ if(angle>360){ angle = angle%360; if (angle == 0){ drawStage(); } } newAngle = angle/180; newAngle = newAngle*Math.PI; return newAngle; } 这个get_attribute("id")函数来获取找到的元素的ID:

WebElement