用python和java写Selenium同样逻辑的,脚本区别

这篇博客探讨了使用Python和Java编写相同逻辑的Selenium脚本的区别。作者通过打开谷歌浏览器并搜索"selenium"的例子,指出Python的脚本相比Java显得更简洁、逻辑更清晰。尽管承认可能是个人Java脚本编写不够优化,但总体上认为Python的关键字与Java大致相似,只是Python更加直观易懂。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

都是自动打开谷歌浏览器

百度进行搜索“selenium”

 

下面是java代码

package cn.sz.Chrome;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;


public class Practice {

	public static void main(String[] args) {
		System.setProperty( "webdriver.chrome.driver", "D:\\selenium-2.53.1\\chromedriver.exe");
		WebDriver driver = new ChromeDriver();
		driver.get("https://www.baidu.com/");
		WebElement input=driver.findElement(By.id("kw"));
		input.sendKeys("seleniummm");
		input.sendKeys(Keys.BACK_SPACE);
		input.sendKeys(Keys.ENTER);
		
	}

}

 

下面是python的代码

from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://www.baidu.com")

driver.find_element_b
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值