Python Selenium修改并运行脚本
我想使用Selenium库通过python在网站上测试脚本。 唯一的问题是,我必须先修改脚本,在运行它之前删除脚本的一部分。 下面是脚本和我想删除的部分 要删除的零件Python Selenium修改并运行脚本,python,selenium,Python,Selenium,我想使用Selenium库通过python在网站上测试脚本。 唯一的问题是,我必须先修改脚本,在运行它之前删除脚本的一部分。 下面是脚本和我想删除的部分 要删除的零件 //alert(data); if(data === 'BAD'){ $('.win_tr').show(); $('.winText').html('<img src="/images/icons/cross.
//alert(data);
if(data === 'BAD'){
$('.win_tr').show();
$('.winText').html('<img src="/images/icons/cross.png" /> Je hebt niet genoeg spins om aan het geluksrad te draaien!');
wheelSpinning = false; // Reset to false to power buttons and spin can be clicked again.
//警报(数据);
如果(数据==‘坏’){
$('.win_tr').show();
$('.winText').html('Je hebt niet genoeg spins om aan het geluksrad te draaien!');
WheelSpiring=false;//重置为false可再次单击电源按钮和旋转。
脚本
<script>
// Create new wheel object specifying the parameters at creation time.
var theWheel = new Winwheel({
'numSegments' : 12, // Specify number of segments.
'outerRadius' : 212, // Set outer radius so wheel fits inside the background.
'textFontSize' : 18, // Set font size as desired.
'textDirection' : 'reversed',
'segments' : // Define segments including colour and text.
[
{'fillStyle' : '#eae56f', 'prize' : '0', 'text' : '10 Eerpunten'},
{'fillStyle' : '#89f26e', 'prize' : '1', 'text' : '10 Credits'},
{'fillStyle' : '#7de6ef', 'prize' : '2', 'text' : '250 Hoeren'},
{'fillStyle' : '#e7706f', 'prize' : '3', 'text' : '$10.000.000'},
{'fillStyle' : '#eae56f', 'prize' : '4', 'text' : 'Geen Prijs'},
{'fillStyle' : '#89f26e', 'prize' : '5', 'text' : '50 Eerpunten'},
{'fillStyle' : '#7de6ef', 'prize' : '6', 'text' : '50 Credits'},
{'fillStyle' : '#e7706f', 'prize' : '7', 'text' : '$25.000.000'},
{'fillStyle' : '#eae56f', 'prize' : '0', 'text' : '250 Hoeren'},
{'fillStyle' : '#89f26e', 'prize' : '1', 'text' : 'Geen Prijs'},
{'fillStyle' : '#7de6ef', 'prize' : '2', 'text' : '500 Hoeren'},
{'fillStyle' : '#e7706f', 'prize' : '3', 'text' : '1000 Hoeren'}
],
'animation' : // Specify the animation to use.
{
'type' : 'spinToStop',
'duration' : 5, // Duration in seconds.
'spins' : 8, // Number of complete spins.
'callbackFinished' : 'alertPrize()'
}
});
// Vars used by the code in this page to do power controls.
var wheelPower = 0;
var wheelSpinning = false;
// -------------------------------------------------------
// Function to handle the onClick on the power buttons.
// -------------------------------------------------------
function powerSelected(powerLevel)
{
// Ensure that power can't be changed while wheel is spinning.
if (wheelSpinning == false)
{
// Reset all to grey incase this is not the first time the user has selected the power.
document.getElementById('pw1').className = "";
document.getElementById('pw2').className = "";
document.getElementById('pw3').className = "";
// Now light up all cells below-and-including the one selected by changing the class.
if (powerLevel >= 1)
{
document.getElementById('pw1').className = "pw1";
}
if (powerLevel >= 2)
{
document.getElementById('pw2').className = "pw2";
}
if (powerLevel >= 3)
{
document.getElementById('pw3').className = "pw3";
}
// Set wheelPower var used when spin button is clicked.
wheelPower = powerLevel;
// Light up the spin button by changing it's source image and adding a clickable class to it.
document.getElementById('spin_button').src = "spin_on.png";
document.getElementById('spin_button').className = "clickable";
}
}
// -------------------------------------------------------
// Click handler for spin button.
// -------------------------------------------------------
function startSpin()
{
// Ensure that spinning can't be clicked again while already running.
if (wheelSpinning == false)
{
// Based on the power level selected adjust the number of spins for the wheel, the more times is has
// to rotate with the duration of the animation the quicker the wheel spins.
if (wheelPower == 1)
{
theWheel.animation.spins = 3;
}
else if (wheelPower == 2)
{
theWheel.animation.spins = 8;
}
else if (wheelPower == 3)
{
theWheel.animation.spins = 15;
}
// Disable the spin button so can't click again while wheel is spinning.
document.getElementById('spin_button').src = "spin_off.png";
document.getElementById('spin_button').className = "";
$.ajax({
url: '/ajax/wheeloffortune.php?getnumber',
type: 'post',
data: {},
dataTupe: 'json',
success: function(data) {
//alert(data);
if(data === 'BAD'){
$('.win_tr').show();
$('.winText').html('<img src="/images/icons/cross.png" /> Je hebt niet genoeg spins om aan het geluksrad te draaien!');
wheelSpinning = false; // Reset to false to power buttons and spin can be clicked again.
}else{
resetWheel();
var stopAt = (data);
// alert(data);
theWheel.animation.stopAngle = stopAt;
// Begin the spin animation by calling startAnimation on the wheel object.
theWheel.startAnimation();
// Set to true so that power can't be changed and spin button re-enabled during
// the current animation. The user will have to reset before spinning again.
wheelSpinning = true;
$.ajax({
url: '/ajax/wheeloffortune.php',
type: 'post',
data: {start_spin:true},
dataTupe: 'json',
success: function(data) {
},
error: function (data) {
// alert('Something went wrong');
$('.win_tr').show();
$('.winText').html('<img src="/images/icons/cross.png" /> Er is iets fout gegaan!');
wheelSpinning = false; // Reset to false to power buttons and spin can be clicked again.
}
});
}
},
error: function (data) {
// alert('Something went wrong');
$('.win_tr').show();
$('.winText').html('<img src="/images/icons/cross.png" /> Er is iets fout gegaan!');
wheelSpinning = false; // Reset to false to power buttons and spin can be clicked again.
}
});
}
}
// -------------------------------------------------------
// Function for reset button.
// -------------------------------------------------------
function resetWheel()
{
theWheel.stopAnimation(false); // Stop the animation, false as param so does not call callback function.
theWheel.rotationAngle = 0; // Re-set the wheel angle to 0 degrees.
theWheel.draw(); // Call draw to render changes to the wheel.
// document.getElementById('pw1').className = ""; // Remove all colours from the power level indicators.
// document.getElementById('pw2').className = "";
// document.getElementById('pw3').className = "";
}
// -------------------------------------------------------
// Called when the spin animation has finished by the callback feature of the wheel because I specified callback in the parameters.
// -------------------------------------------------------
function alertPrize()
{
// Get the segment indicated by the pointer on the wheel background which is at 0 degrees.
var winningSegment = theWheel.getIndicatedSegment();
// Do basic alert of the segment text. You would probably want to do something more interesting with this information.
// alert("You have won " + winningSegment.text);
var winText = winningSegment.text;
var winPrize = winningSegment.prize;
$.ajax({
url: '/ajax/wheeloffortune.php',
type: 'post',
data: {text:winText, prize_won:winPrize},
dataTupe: 'json',
success: function(data) {
var data = jQuery.parseJSON(data);
// Show whole array
var data2 = JSON.stringify(data);
// console.log(data2);
// De win tekst
var winText = data['tekst'];
var status = data['status'];
var likes2 = data['prize'];
var new_spins = $('.spins').text() - 1;
if(new_spins < 0) {
new_spins = 0;
}
$('.spins').html(new_spins);
$('.win_tr').show();
if(status = 'OK' && winText !== 'BAD') {
$('.winText').html('<img src="/images/icons/tick.png" /> ' + winText + '');
}else{
$('.winText').html('<img src="/images/icons/cross.png" /> Er is iets fout gegaan!');
}
wheelSpinning = false; // Reset to false to power buttons and spin can be clicked again.
},
error: function (data) {
//alert('Something went wrong');
$('.win_tr').show();
$('.winText').html('<img src="/images/icons/cross.png" /> Er is iets fout gegaan!');
wheelSpinning = false; // Reset to false to power buttons and spin can be clicked again.
}
});
}
//创建新的控制盘对象,在创建时指定参数。
var theWheel=新Winwheel({
“numSegments”:12,//指定段数。
“outerRadius”:212,//设置外半径,使轮子适合背景。
'textFontSize':18,//根据需要设置字体大小。
“textDirection”:“reversed”,
“segments”:定义包括颜色和文本在内的段。
[
{'fillStyle':'eae56f','prize':'0','text':'10eerpunten'},
{'fillStyle':'#89f26e','prize':'1','text':'10学分',
{'fillStyle':'7de6ef','prize':'2','text':'250 Hoeren'},
{'fillStyle':'e7706f','prize':'3','text':'10.000.000'},
{'fillStyle':'eae56f','prize':'4','text':'Geen Prijs'},
{'fillStyle':'#89f26e','prize':'5','text':'50eerpunten'},
{'fillStyle':'7de6ef','prize':'6','text':'50 Credits'},
{'fillStyle':'e7706f','prize':'7','text':'25000.000'},
{'fillStyle':'eae56f','prize':'0','text':'250 Hoeren'},
{'fillStyle':'#89f26e','prize':'1','text':'Geen Prijs'},
{'fillStyle':'7de6ef','prize':'2','text':'500 Hoeren'},
{'fillStyle':'e7706f','prize':'3','text':'1000 Hoeren'}
],
'animation'://指定要使用的动画。
{
'type':'spinToStop',
“持续时间”:5,//持续时间(秒)。
“旋转”:8,//完成旋转的数量。
“CallImpactFinished”:“alertPrize()”
}
});
//此页中的代码用于执行电源控制的变量。
无功功率=0;
var-wheelspining=false;
// -------------------------------------------------------
//功能处理电源按钮上的onClick。
// -------------------------------------------------------
功能选择(功率级)
{
//确保车轮旋转时不能改变电源。
如果(车轮打滑==错误)
{
//如果这不是用户第一次选择电源,请将全部重置为灰色。
document.getElementById('pw1')。className=“”;
document.getElementById('pw2')。className=“”;
document.getElementById('pw3')。className=“”;
//现在点亮下面的所有单元格,包括通过更改类选择的单元格。
如果(功率级>=1)
{
document.getElementById('pw1').className=“pw1”;
}
如果(功率级>=2)
{
document.getElementById('pw2').className=“pw2”;
}
如果(功率级>=3)
{
document.getElementById('pw3').className=“pw3”;
}
//设置单击旋转按钮时使用的wheelPower var。
车轮功率=功率级;
//通过更改旋转按钮的源图像并向其添加可单击的类来点亮旋转按钮。
document.getElementById('spin_button').src=“spin_on.png”;
document.getElementById('spin_按钮')。className=“可点击”;
}
}
// -------------------------------------------------------
//单击旋转按钮的处理程序。
// -------------------------------------------------------
函数startSpin()
{
//确保在已运行时不能再次单击旋转。
如果(车轮打滑==错误)
{
//根据选择的功率级别调整车轮的旋转次数,所需的次数越多
//要随动画的持续时间旋转,轮子旋转得越快。
如果(车轮功率==1)
{
theWheel.animation.spins=3;
}
否则如果(车轮功率==2)
{
theWheel.animation.spins=8;
}
否则如果(车轮功率==3)
{
theWheel.animation.spins=15;
}
//禁用“旋转”按钮,以便在轮子旋转时不能再次单击。
document.getElementById('spin_button').src=“spin_off.png”;
document.getElementById('spin_按钮')。className=“”;
$.ajax({
url:“/ajax/wheeloffort.php?getnumber”,
键入:“post”,
数据:{},
dataTupe:'json',
成功:功能(数据){
//警报(数据);
如果(数据==‘坏’){
$('.win_tr').show();
$('.winText').html('Je hebt niet genoeg spins om aan het geluksrad te draaien!');
WheelSpiring=false;//重置为false可再次单击电源按钮和旋转。
}否则{
重置车轮();
var stopAt=(数据);
//警报(数据);
theWheel.animation.stopAngle=stopAt;
//通过调用控制盘对象上的startAnimation开始旋转动画。
车轮开始转动();
//设置为true,以便在运行期间不能更改电源和重新启用旋转按钮
//当前动画。用户必须在再次旋转之前重置。
车轮旋转=正确;
$.ajax({
url:“/ajax/wheeloffort.php”,
键入:“post”,
数据:{start_spin:true},