如何解决如何单击硒表中的图像
在网页上,我有3个按钮,在表格中有一个链接图像。但是我找不到带有按钮“发送”的图像
以下是表格中嵌入的HTML代码:
<a class="ctl00_C_S_Z_ctrlActionToolbar_Menu1_1" href="javascript: ValidateSendMessage()>
<img src="ShmControls/ShmImages/SHM_Send_Trans.png" alt="Send Message" style="border-style:none;vertical-align:middle;>"Send" /a>
让我知道如何在网页上找到该按钮?
我尝试了以下所有选项来定位图像元素
IWebElement Send = driver.FindElement(By.XPath("a[@href= 'javascript: ValidateSendMessage()')]"));
IWebElement Send = driver.FindElement(By.XPath("//img[contains(src,'ShmControls/ShmImages/SHM_Send_Trans.png')]"));
IWebElement Send = driver.FindElement(By.XPath("//*@id='ctl00_C_S_Z_ctrlActionToolbar_Menu1']"));
IWebElement Send = driver.FindElement(By.LinkText("ShmControls/ShmImages/SHM_Send_Trans.png"));
解决方法
要单击文本为发送的WebElement,可以使用以下任一Locator Strategies:
-
使用 CssSelector :
import Vue from "vue"; import Vuex from "vuex"; import * as fb from "../firebase"; import router from "../router/index"; Vue.use(Vuex); // realtime firebase connection fb.postsCollection.orderBy("createdOn","desc").onSnapshot((snapshot) => { let postsArray = []; snapshot.forEach((doc) => { let post = doc.data(); post.id = doc.id; postsArray.push(post); }); store.commit("setPosts",postsArray); }); const store = new Vuex.Store({ state: { userProfile: {},posts: [],},mutations: { setUserProfile(state,val) { state.userProfile = val; },setPosts(state,val) { state.posts = val; },actions: { async signup({ dispatch },form) { // sign user up const { user } = await fb.auth.createUserWithEmailAndPassword( form.email,form.password ); // create user profile object in userCollections await fb.usersCollection.doc(user.uid).set({ name: form.name,title: form.title,}); // fetch user profile and set in state dispatch("fetchUserProfile",user); },async login({ dispatch },form) { // sign user in const { user } = await fb.auth.signInWithEmailAndPassword( form.email,form.password ); // fetch user profile and set in state dispatch("fetchUserProfile",async logout({ commit }) { await fb.auth.signOut(); // clear userProfile and redirect to /login commit("setUserProfile",{}); router.push("/login"); },async fetchUserProfile({ commit },user) { // fetch user profile const userProfile = await fb.usersCollection.doc(user.uid).get(); // set user profile in state commit("setUserProfile",userProfile.data()); // change route to dashboard if (router.currentRoute.path === "/login") { router.push("/"); } },async createPost({ state },post) { await fb.postsCollection.add({ createdOn: new Date(),content: post.content,userId: fb.auth.currentUser.uid,userName: state.userProfile.name,comments: 0,likes: 0,}); },async likePost(context,{ id,likesCount }) { const userId = fb.auth.currentUser.uid; const docId = `${userId}_${id}`; // check if user has liked post const doc = await fb.likesCollection.doc(docId).get(); if (doc.exists) { return; } // create post await fb.likesCollection.doc(docId).set({ postId: id,userId: userId,}); // update post likes count fb.postsCollection.doc(id).update({ likes: likesCount + 1,async updateProfile({ dispatch },user) { const userId = fb.auth.currentUser.uid; // update user object /*const userRef = */await fb.usersCollection.doc(userId).update({ name: user.name,title: user.title,}); dispatch("fetchUserProfile",{ uid: userId }); // update all posts by user const postDocs = await fb.postsCollection .where("userId","==",userId) .get(); postDocs.forEach((doc) => { fb.postsCollection.doc(doc.id).update({ userName: user.name,}); }); // update all comments by user const commentDocs = await fb.commentsCollection .where("userId",userId) .get(); commentDocs.forEach((doc) => { fb.commentsCollection.doc(doc.id).update({ userName: user.name,}); }); },modules: {},}); export default store;
-
使用 XPath :
Fetching user profile.. Settings.vue?e12e:29 Setting Data... index.js?4360:75 Performing setUserProfile commit.. index.js?4360:29 Setting user profile in state,last step..
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。